全部博文(136)
分类: Java
2011-03-30 10:48:07
How do I write and run a simple test?
Create a class:
Write a test method (annotated with @Test) that asserts expected results on the object under test:
If you are running your JUnit 4 tests with a JUnit 3.x runner, write a suite() method that uses the JUnit4TestAdapter class to create a suite containing all of your test methods:
Although writing a main() method to run the test is much less important with the advent of IDE runners, it's still possible:
Run the test:
To run the test from the console, type:
java org.junit.runner.JUnitCore junitfaq.SimpleTest
To run the test with the test runner used in main(), type:
java junitfaq.SimpleTest
The passing test results in the following textual output:
.
Time: 0
OK (1 tests)