java - JUnit confusion: use 'extends TestCase' or '@Test'? - Stack Overflow
- extending
TestCase
is the way unit tests were written in JUnit 3 (of course it's still supported in JUnit 4) - using the
@Test
annotation is the way introduced by JUnit 4
Generally you should choose the annotation path, unless compatibility with JUnit 3 (and/or a Java version earlier than Java 5) is needed. The new way has several advantages:
- The
@Test
annotaton is more explicit and is easier to support in tools (for example it's easy to search for all tests this way) - Multiple methods can be annotated with
@Before
/@BeforeClass
and@After
/@AfterClass
providing more flexibility - Support for
@Rule
annotations on things likeExpectedException
- Support for the
@Ignored
annotation - Support for alternative test runners using
@RunWith
Read full article from java - JUnit confusion: use 'extends TestCase' or '@Test'? - Stack Overflow
No comments:
Post a Comment