I have (Test-A) fully annotated testng test in one project. Note: this test runs successfully. Then I have another testng test (Test-B) in a different project extending (Test-A). This new (Test-B) does not have any annotations since its extending a class that does. My expectation is that when you run this test (Test-B), it should run the test-cases in the super class in addition to the testcase defineed within it which is the object-oriented way. The problem is that testng does not even recognize it as test since there is no annotation within it. I guess testng annotation processing does not consider super-class's annotation??
(Note, using plain old JUnit 4 here, not TestNG)
Eclipse does appear to look up the class hierarchy for @Test annotations if the parent class is in the same project. The following example worked for me:
public class A {
@Test public void a() {
}
}
public class B extends A {
}
When running B
as a JUnit Test, it executes a()
and passes.
I then created two Eclipse projects, Test A and Test B. I made project B link to project A and repeated the above steps like you did, with class A in project A etc. Now, running class B as a unit test says 'No JUnit tests found.' Then, adding a @Test
to class B solves the problem.
So, we can deduce that Eclipse doesn't leave the bounds of the current project when looking for test cases. I think your workaround of adding a single @Test
to your class is a reasonable one, although I'm not sure why you would want to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With