Test the combination of multiple single sample test kits together.
There are mytest, testmain two classes, the code is as follows:
Package test; Import Junit.framework.Assert; Import Junit.framework.Test; Import Junit.framework.TestCase; Import Junit.framework.TestSuite; public class MyTest extends testcase{protected void setUp () {System.out.println ("=====setup======");} protected void Tea Rdown () {System.out.println ("=====teardown======");} public MyTest (String name) {super (name);} public void Testmethoda () {System.out.println ("=====testmethoda start======"); Assertequals ("It is isn't equal from constant", "123", "123"); System.out.println ("=====testmethoda end======"); public void Testmethodb () {System.out.println ("=====testmethodb start======"); Failnotsame ("It's not equal from string Object ", new String (" 123 "), new String (" 12 ")); System.out.println ("=====testmethodb middle======"); Assertequals ("It isn't equal from string object", new String ("123"), new String ("123")); System.out.println ("=====testmethodb end======"); public void Test () {System.out.println ("=====testmethodc start======"); Assertequals ("Itis isn't equal from string object, new String ("123"), new String ("123")); System.out.println ("=====testmethodc end======"); public static void Main (String args[]) {TestCase test= new MyTest (' my test ') {public void Runtest () {Testmethoda ()} }; Junit.textui.TestRunner.run (test); //junit runtime, the main method of the equivalent normal class is public static Test suite () {System.out.println ("Start Suite:"); return new TestSuite (Mytest.class); With class as Parameter}}
Package test; Import Junit.framework.Test; Import Junit.framework.TestCase; Import Junit.framework.TestSuite; /** * * * @author ZCB * */public class Testmain extends testcase{public void Testmethoda () {System.out.println ("=====testm Ain.testmethoda start====== "); Assertequals ("It isn't equal from constant", "123", "123"); System.out.println ("=====testmain.testmethoda end======"); }//public static void Main (String args[]) {////TestCase test= new MyTest () {////public void Runtest () {////Testmeth OdA (); //// } //// //// }; TestCase test= New MyTest ("Testmethoda"); Junit.textui.TestRunner.run (test); The public static Test suite () {TestSuite suite= new TestSuite (), Suite.addtest (New MyTest ("My Test") {protected voi D runtest () {Testmethoda (); Testmethodb ();}} ); Suite.addtest (New Testmain () {protected void Runtest () {Testmethoda ();}}); System.out.println ("Test count:" +suite.testcount ()); return suite; } }
The normal run output is as follows:
. =====setup======
=====testmethoda start======
=====testmethoda end======
=====teardown======
time:0
JUnit runs the output as follows:
Test Count:2
=====setup======
=====testmethoda start======
=====testmethoda end======
=====testmethodb start======
=====teardown======
=====testmain.testmethoda start======
=====testmain.testmethoda end======
Resources Address: Http://wenku.baidu.com/view/3504b7f8941ea76e58fa04f8.html