Testng works with test inheritance

Hey guys, my question is simple and straightforward. I have such a scenario.

I have a (Test-A) fully annotated testng test in one project. Note: this test is successful. Then I have another testng test (Test-B) in another project extending (Test-A) . This new (Test-B) has no annotations as it extends the class that it does. I expect that when you run this test (Test-B) , it should run test cases in the superclass in addition to the test defined inside it, which is an object-oriented way. The problem is that testng does not even recognize it as a test, since it does not have an annotation. I think that processing testng annotation does not account for superclass annotation

+5
source share
1 answer

(Note that the plain old JUnit 4 is used here, not TestNG)

Eclipse seems to be looking for a 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 run Bas a JUnit test, it executes a()and passes.

Then I created two Eclipse projects, Test A and Test B. I made a link from project B to project A and repeated the above steps, as you did, with class A in project A, etc. Now starting class B as a unit test says: "There are no JUnit tests." Then adding a @Testto class B solves the problem.

, , Eclipse . , @Test , , .

+2

All Articles