TNG / value-provider

Apache License 2.0
5 stars 3 forks source link

IllegalStateException if using inner test-classes and ValueProviderExtension been declared on top-level #40

Open yobinx opened 3 weeks ago

yobinx commented 3 weeks ago

Having inner classes inside the test and the ValueProviderExtension is been declared on the top-level class, e.g.:

@ExtendWith(ValueProviderExtension.class)
class MyTestClass {

    @Nested
    class MyInnerTestClass1 {
        @Test
        void test() {
        }
    }

    @Nested
    class MyInnerTestClass2 {
        @Test
        void test() {
        }
    }
}

Then the following exception is been thrown:

java.lang.IllegalStateException: Illegal transition, cannot switch from DEFAULT back to TEST_CLASS
    at com.google.common.base.Preconditions.checkState(Preconditions.java:836)
    at com.tngtech.valueprovider.ValueProviderFactory.checkMayFinish(ValueProviderFactory.java:90)
    at com.tngtech.valueprovider.ValueProviderFactory.doFinishTestClassCycle(ValueProviderFactory.java:62)
    at com.tngtech.valueprovider.ValueProviderFactory.finishTestClassCycle(ValueProviderFactory.java:152)
    at com.tngtech.valueprovider.ValueProviderExtension.finishTestClassCycle(ValueProviderExtension.java:115)
    at com.tngtech.valueprovider.ValueProviderExtension.afterAll(ValueProviderExtension.java:99)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
jonashoef commented 2 days ago

Thank you for bringing this deficiency up, @yobinx, and please forgive me for my late response. According to my first, admittedly rough analysis, adding support for @Nested inner test classes should be possible. I will get back to you as soon as I have a working solution.