org.openrewrite.java.testing.junit5.AddMissingNested recipe adds @Nested to abstract classes and ignores effectively-@Nested subclasses that don't have their own @Test methods but inherit some from their superclasses.
@Nested on abstract class causes java.lang.InstantiationException at runtime.
See junit-team/junit-framework#2717, or junit-team/junit-framework#2717 (comment) more specifically for explanation.
Missing @Nested on a class which doesn't have its own @Test methods but inherits @Test methods from its possible abstract superclasses leads to missed tests - this non-annotated class will not be detected by JUnit 5.
What version of OpenRewrite are you using?
- rewrite-maven-plugin 6.11.0
- rewrite-testing-frameworks 3.10.0
What is the smallest, simplest way to reproduce the problem?
import org.junit.jupiter.api.Test;
public class AddMissingNestedTest {
abstract class CommonNestedBase {
@Test
void commonNestedTest() {
}
}
class NestedTest extends CommonNestedBase {
}
}
What did you expect to see?
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
public class AddMissingNestedTest {
abstract class CommonNestedBase {
@Test
void commonNestedTest() {
}
}
@Nested
class NestedTest extends CommonNestedBase {
}
}
What did you see instead?
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
public class AddMissingNestedTest {
@Nested
abstract class CommonNestedBase {
@Test
void commonNestedTest() {
}
}
class NestedTest extends CommonNestedBase {
}
}
Seems like the case with adding @Nested to abstract class can be solved by adding the corresponding check near https://github.com/openrewrite/rewrite-testing-frameworks/blob/main/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java#L90.
Right now I am not sure how to approach the case with nested test class without test methods that inherits test methods for some of its superclasses.
org.openrewrite.java.testing.junit5.AddMissingNestedrecipe adds@Nestedto abstract classes and ignores effectively-@Nestedsubclasses that don't have their own@Testmethods but inherit some from their superclasses.@Nestedon abstract class causesjava.lang.InstantiationExceptionat runtime.See junit-team/junit-framework#2717, or junit-team/junit-framework#2717 (comment) more specifically for explanation.
Missing
@Nestedon a class which doesn't have its own@Testmethods but inherits@Testmethods from its possible abstract superclasses leads to missed tests - this non-annotated class will not be detected by JUnit 5.What version of OpenRewrite are you using?
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
Are you interested in contributing a fix to OpenRewrite?
Seems like the case with adding
@Nestedto abstract class can be solved by adding the corresponding check near https://github.com/openrewrite/rewrite-testing-frameworks/blob/main/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java#L90.Right now I am not sure how to approach the case with nested test class without test methods that inherits test methods for some of its superclasses.