Basic question on JUnit
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ravi_Kota
Posted On:   Tuesday, July 1, 2008 10:08 AM

Hi, This may sound very basic question related to JUnit Test Suite , but believe me I'm not able to understand it. As part of my project (For which I do not currently have access to do trial run), I was going through existing testing frame work and the flow is as below : There is a base class extending TestCase say public class ParentTest extends TestCase{ public ParentTest(){ try { init(); } catch (Exception e) { e.printStackTrace(); } } public ParentTest( String name ) { super( name ); } public static v   More>>

Hi,

This may sound very basic question related to JUnit Test Suite , but believe me I'm not able to understand it. As part of my project (For which I do not currently have access to do trial run), I was going through existing testing frame work and the flow is as below :

There is a base class extending TestCase say



public class ParentTest extends TestCase{


public ParentTest(){


try {


init();


}


catch (Exception e) {


e.printStackTrace();


}


}


public ParentTest( String name ) {


super( name );


}


public static void main(String args[]) {

junit.textui.TestRunner.run( suite() );


}


public static Test suite() {


return( new TestSuite( ParentTest.class ) );


}


public void init() {
/* This method is using
Reflection API to find out all testcase methods */ }



/* Remaining part of the code*/}









But the above class does not have any methods beginning with test, so there are no Test methods and apparently when we run this class, we get a message that no tests found.



public class ChildTestCase extends ParentTest{


Pblic static void main(String args[]) {



junit.textui.TestRunner.run( suite() );

}

public static Test suite() {

return( new TestSuite( ParentTest.class ) );

}

public ChildTestCase() { super(); }
public ChildTestCase(String name) {

super( name );

}

public void testMethodA(){ }

public void testMethodB(){ }

public void testMethodC(){ }

}






My question was, when would init() method be called as it is called from No-Arg constructor. Why is the statement return( new TestSuite( ParentTest.class ) );
there in ChildTestCase and apparently this should also throw an error as ParentTest does not have any methods beginning with test.

Can some one throw some light on this?

Thanks

   <<Less
About | Sitemap | Contact