juint2.* Suite Test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.