Testing

top down
+can use whole program testcases
+earlier demo
-complicated stubs
-stubs needed
-testing stubs not real modules


bottom up
+no stub needed
+test component for reuse
+real test data
-error found late
-drivers need to be made

suggested: bottom up

if you need a module, you should write the test for that
give stubs to those that need your stub



JUnit
One of the most useful testing facilities - can handle white box testing as well as black box

EclEmma
One of the best tools, code coverage analysis

JUnit in Eclipse

Make a new source folder, name it test
Right click on the class you want to test: New -> JUnit Test Case
Choose the source folder the test folder
Click Next, Choose the methods you want to test
Finish
In the created test class right click, Run As -> JUnit Test

To test the method you can use methods like  assertTrue(a.hasA()); or other assert.... method series.


To test methods that use System.in
String data = "Hello, World!\r\n";
InputStream stdin = System.in;
try {
 
System.setIn(new ByteArrayInputStream(data.getBytes()));
 
Scanner scanner = new Scanner(System.in);
 
System.out.println(scanner.nextLine());
} finally {
 
System.setIn(stdin);
}


Sonar (Code Coverage), Coverity (Code Analyzer



Comments