Start JUnit4
Let’s make JUnit4 Testing
Steps
- Add JUnit4 library
- Create test method using @Test annotation
Add JUnit4 Build Path
JUnit4 libraries are in eclipse plugin by default.
Eclipse -> “Properties” -> “Java Build Path” -> “Add Library…” -> “JUnit”
You can select JUnit3 or JUnit4.
Select JUnit4.
After that you can see JUnit4 under Referenced Library of project
Simple JUnit Test
This is first sample of JUnit Test.
Version 4 become very simple. In 3, you need to extend TestCase.
In 4, you just only add annotation(@Test) to test method.
public class FirstTest { @Test public void firstTest() { } public void noTest() { } }
In this sample, firstTest is test method.
On the other hand, noTest is not test method.(Ignored when running test).
How to run?
Eclipse -> “Run” -> “Debug As” -> “JUnit”
It’s same as JUnit3.