-
Notifications
You must be signed in to change notification settings - Fork 261
TestFeatureManager in JUnit 5 nested class is empty #1135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The general solution to this problem is to use the annotation on ALL the classes that make use of the functionality in their root, including the nested classes. So the code would have to be something like this: package example;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import example.TestFeatureManagerTest.SomeFeatures;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.togglz.core.Feature;
import org.togglz.junit5.AllEnabled;
@AllEnabled(SomeFeatures.class)
class TestFeatureManagerTest {
@Test
void someTest(org.togglz.testing.TestFeatureManager featureManager) {
assertThat(featureManager, is(notNullValue()));
}
@Nested
@AllEnabled(SomeFeatures.class)
class someNestedClass {
@Test
void someTest(org.togglz.testing.TestFeatureManager featureManager) {
assertThat(featureManager, is(notNullValue()));
}
}
public enum SomeFeatures implements Feature {
}
} Specific solutionAnd since you only want to use package example;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.togglz.core.Feature;
import org.togglz.junit5.AllEnabled;
class TestFeatureManagerTest {
// Other nested classes
@Nested
@AllEnabled(SomeFeatures.class)
class someNestedClass {
@Test
void someTest(org.togglz.testing.TestFeatureManager featureManager) {
assertThat(featureManager, is(notNullValue()));
}
}
public enum SomeFeatures implements Feature {
}
} General structureAnd for clarity here is another example that should fit most cases: package example;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.togglz.core.Feature;
import org.togglz.junit5.AllEnabled;
// AllEnabled annotation is only needed if you also want to use the TestFeatureManager in the root of this class
class TestFeatureManagerTest {
// Only test in root of the class and doesn't use the TestFeatureManager
@Test
void someTest() {
assertThat("Check this out, I'm being asserted!", is(notNullValue()));
}
@Nested
@AllEnabled(SomeFeatures.class)
class someNestedClassOne {
@Test
void someNestedTest(org.togglz.testing.TestFeatureManager featureManager) {
assertThat(featureManager, is(notNullValue()));
}
}
@Nested
@AllEnabled(SomeFeatures.class)
class someNestedClassTwo {
@Test
void someNestedTest(org.togglz.testing.TestFeatureManager featureManager) {
assertThat(featureManager, is(notNullValue()));
}
}
@Nested
class someNestedClassThree {
// Doesn't use the TestFeatureManager
@Test
void someNestedTest() {
assertThat("Me too!", is(notNullValue()));
}
}
public enum SomeFeatures implements Feature {
}
} |
When using the
org.togglz.testing.TestFeatureManager
in aorg.junit.jupiter.api.Nested
test class, the feature manager is empty.For example:
The method
example.TestFeatureManagerTest#someTest
succeeds, howeverexample.TestFeatureManagerTest.someNestedClass#someTest
fails becausefeatureManager
isnull
.I would expect that this would work in a nested class as well.
The text was updated successfully, but these errors were encountered: