Junit3: TestSuite, , TestCase . JVM, TestCase (setUp, tearDown , , , , ..).
, TestCase , .
suite() TestSuite. Ant JUnit , , .
public class DynamicTest extends TestCase {
String filename ;
public DynamicTest ( String crntFile ) {
super("testMethod");
filename = crntFile ;
}
public String getName() {
return this.getClass().getName() + " : " + filename ;
}
public void testMethod() {
File f = new File( filename ) ;
assertTrue( f.exists() ) ;
}
public static TestSuite suite() {
TestSuite s = new TestSuite() ;
for ( String crntFile : getListOfFiles() ) {
s.addTest( new DynamicTest(crntFile ) ) ;
}
return s ;
}
}
Of course, you can separate TestSuite from TestCase if you want. However, TestCase does not stand still, so you will need to be careful about naming conventions if your tests are automatically detected.
source
share