Reputation: 11
I have a class C which must extend a class N because it provides functionality I must have. I want C to be a JUnit test so I want to extend TestCase, because I am using a test executor, a Junit suite object, which requires tests being added to be it to be of type TestCase. This means that I have to use the TestCase extension.
Java, however, does not allow for multiple inheritance, so I need to, instead, use an interface. Is there an existing interface? Or is there a way to dynamically execute Junit tests that don't extend from TestCase?
Upvotes: 1
Views: 449
Reputation: 189
Do you really need your C class to extend N? Can't you just opt for composition instead of extension? Your C could have N as internal attribute and be using the functionalities provided by it. Just an idea.
Upvotes: 1
Reputation: 21194
The interface is called Test
, see: http://junit.sourceforge.net/junit3.8.1/javadoc/junit/framework/Test.html
However, in newer versions of JUnit you should definitely go for the @Test attribute and add your test classes to your suite by specifying the type via YourTestClass.class
Upvotes: 0
Reputation: 308733
I don't extend Test
or TestCase
anymore. I use the @Test
annotations since version 4.4.
Upvotes: 1