@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment= RANDOM_PORT) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:applicationContext.xml"})
JUnit 5web
@ExtendWith(SpringExtension.class) @TestPropertySource(locations = { "/application.properties" }) @Import({EnvironmentConfig.class}) @ContextConfiguration(classes = { XXXConfig.class, YYYConfig.class }) @TestInstance(Lifecycle.PER_CLASS) public class XXXTest { private static final Logger logger = LoggerFactory.getLogger(XXX.class); @Autowired private XXXActions xxxActions; @BeforeAll public void setUp() throws Exception { } @AfterAll public void afterAll() throws Exception { } @Test public void testYYY() throws InterruptedException { } }
結合Mavenspring
<!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.0</version> </plugin> </plugins> </build>