spring junit config (#3124)

This commit is contained in:
Marcos Lopez Gonzalez 2017-11-29 09:53:43 +01:00 committed by Grzegorz Piwowarek
parent 1854175cb9
commit d10a8d7f47
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package com.baeldung.jupiter;
import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @SpringJUnitConfig(SpringJUnitConfigTest.Config.class) is equivalent to:
*
* @ExtendWith(SpringExtension.class)
* @ContextConfiguration(classes = SpringJUnitConfigTest.Config.class )
*
*/
@SpringJUnitConfig(SpringJUnitConfigTest.Config.class)
public class SpringJUnitConfigTest {
@Configuration
static class Config {
}
@Autowired
private ApplicationContext applicationContext;
@Test
void givenAppContext_WhenInjected_ThenItShouldNotBeNull() {
assertNotNull(applicationContext);
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.jupiter;
import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.web.context.WebApplicationContext;
/**
* @SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class) is equivalent to:
*
* @ExtendWith(SpringExtension.class)
* @WebAppConfiguration
* @ContextConfiguration(classes = SpringJUnitWebConfigTest.Config.class )
*
*/
@SpringJUnitWebConfig(SpringJUnitWebConfigTest.Config.class)
public class SpringJUnitWebConfigTest {
@Configuration
static class Config {
}
@Autowired
private WebApplicationContext webAppContext;
@Test
void givenWebAppContext_WhenInjected_ThenItShouldNotBeNull() {
assertNotNull(webAppContext);
}
}