spring junit config (#3124)
This commit is contained in:
parent
1854175cb9
commit
d10a8d7f47
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue