java - JUnit confusion: use 'extends TestCase' or '@Test'? - Stack Overflow
- extending
TestCaseis the way unit tests were written in JUnit 3 (of course it's still supported in JUnit 4) - using the
@Testannotation 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
@Testannotaton 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/@BeforeClassand@After/@AfterClassproviding more flexibility - Support for
@Ruleannotations on things likeExpectedException - Support for the
@Ignoredannotation - 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