Skip to content
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

Support for nested tests #8

Closed
czietsman opened this issue Mar 1, 2017 · 3 comments
Closed

Support for nested tests #8

czietsman opened this issue Mar 1, 2017 · 3 comments

Comments

@czietsman
Copy link

czietsman commented Mar 1, 2017

I've been playing with JUnit 5 and spring-test-junit5. I then tried to use the nested tests feature, but my tests fail. This also happens when I run directly from the command line using gradle.

	@ExtendWith(SpringExtension.class)
	@ContextConfiguration(classes = TestConfig.class)
	@DisplayName("In cat club")
	public class NestedCatTests {
	    @Autowired
	    Cat cat;
	
	    @Autowired
	    List<Cat> cats;
	
	    @Test
	    @DisplayName("Catbert is the cat")
	    void catWasAutowired() {
	        assertEquals(
	                "Catbert",
	                cat.getName()
	        );
	    }
	
	    @Nested
	    @DisplayName("Catbert")
	    class IsMemberOfClub {
	        @Test
	        @DisplayName("is a member")
	        void isMemberOf() {
	            assertTrue(cats.contains(cat));
	        }
	    }
	}

I get the following exception:

	java.lang.IllegalStateException: Failed to load ApplicationContext
	
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
	at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:91)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$null$1(ClassTestDescriptor.java:196)
	at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:102)
	...
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
	
	Caused by: java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to load an ApplicationContext from [MergedContextConfiguration@4816278d testClass = NestedCatTests.IsMemberOfClub, locations = '{}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]].
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:263)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	... 44 more

I've managed to get it to work if I add @ContextConfiguration(classes = TestConfig.class) to the nested class. I think however that support could be improved to resolve the configuration from the enclosing class.

@sbrannen
Copy link
Owner

Thanks for raising the issue!

However, this code base is not actively maintained: it has been moved to the spring-test module in the Spring Framework.

Would you mind creating an issue against the "Spring Framework" and its "Test" component here?

@sbrannen
Copy link
Owner

FYI: this is somewhat related to SPR-14150.

@sbrannen
Copy link
Owner

Closing in lieu of SPR-15366.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants