Fitnesse : How to verify sorting order ?

When query fixture is executed, the return result set is verified against the presence or absence of the element without considering the order in which the element appears. It makes it difficult to verify to the sorting order. The good news is that with a little work around it can achieved without much efforts.

fitnesse order

The trick is to append the sequence number appended in the title string of the elements in the wiki page. In the fixture code before returning the result set, append the sequence let’s say “for 1=1 to 10” and validate against wiki page. In this case let’s say the title you are expecting to be at top with sequence number “1 the title” comes down to appear at “4 the title” the test case will get failed. This way the sequence can be verified easily by appending the expected sequence with the title.

fixture code to sort order

TestNG : Expected Exception Test

It is always good to test the working and output of your unit. But it is more important to test the negative behavior to make application robust. What if you are expecting an exception from a part of code which is not thrown. the point where application has to get terminated, it is moving smoothly to get a dead lock or a pitty crash. Just to save such situation Testing of exception generation is code is very important. There are annotation in TestNG frame work which helps to make is an easy task.

Example

import org.testng.annotations.*;

public class TestNGTest2 {

	@Test(expectedExceptions = ArithmeticException.class)  
	public void divisionWithException() {  
	  int i = 1/0;
	}  

}

In above example, the divisionWithException() method will throw an ArithmeticException Exception, since this is an expected exception, so the unit test will pass.

More advanced example can be observed in the snap shot attached.
Where the scenarios to test says – “Calling this method with null argument throws Exception”.
The test will go green if exception is thrown, else it will go red.

Testing the expected exception

Testing the expected exception