1. Introduction to JUnit JUnit is based on an object-oriented Java unit test framework. JUnit is an open source project that can be extended as needed. Second, install JUnit first get the JUnit package, download the latest package from http://www.junit.org. Unpack the package in the appropriate directory. This finds a file called JUnit.jar in the installation directory, add this JAR file to the ClassPath system variable. Third, JUnit Framework introduction: 1) TestCase - Test cases, to define a test case. JUnit supports two methods of running a single test: static and dynamic methods. 1, static method is to cover the RUNTEST () method of the TestCase class, which is generally created by an internal class: testcase test01 = new testcar ("test getwheels") {public void runtest () {testGetWheels (); } With static ways to pay attention to give each test one name so you can distinguish from which test failed. 2, the dynamic method is to implement RUNTEST () in the order to create a test instance. This requires the name of the test, is the name of the test method that needs to be called: TestCase Test01 = New TestCar ("TestGetWheels"); JUnit will dynamically find and call the specified test method. The dynamic method is very concise, but if you type the wrong name, you will get a strange NosuchMethodeXception exception. Dynamic methods and static methods are very good, you can choose according to your own preferences. 2) TestSuite once you created some test instances, the next step is to let them run together. We must define a TestSuite. In JUnit, this requires you to define a static suite () method in the TestCase class. The suite () method is like the Main () method, JUnit uses it to perform tests. In the suite () method, you add a test instance to a TestSuite object and return to this TestSuite object. A TestSuite object can run a set of tests. TestSuite and TestCase have implemented TEST interfaces, and the Test interface defines the methods required to run tests. This allows you to create a TestSuite with a combination of TestCase and TestSuite. Public static test suite () {testsuite suite = new testsuite (); suite.addtest (new testcar ("testcar (" testcar ("testcar (" testcar)); return suite;} public static test suite ) {Return New Testsuite;} 3) Testrunner has TestSuite We can run these tests, Junit provides three interfaces to run test [Text ui] junit.textui.teStrunner [AWT UI] junit. AWTUI.TESTRUNNER [SWING ui] junit.swingui.testrunner java junit.textui.teestrunner YourTestClass fixture If you need to perform multiple tests in one or several classes, these classes become Tested Context. In JUNIT, it is called fixture. When you write a test code, you will find that you spend a lot of time configuration / initialization related tests of FixTure.