我们正在使用spring webflux从头开始创建产品。我们正在编写单元测试用例。尽管我可以在导入中获取Spring Application主类,但是当我们运行mvn clean install
时,它会继续告诉Compilation failure, cannot find class
。我们该如何克服呢?
我的项目结构是
Application
-app-web-module
-src/java/com/org/SpringApplicationClass
-pom.xml
-app-web-unitcases
-src/test/com/org/mytestclass
-pom.xml
我的测试班是
@TestPropertySource(properties = "CONFIG_ENVIRONMENT=ci")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ContextConfiguration(classes = com.org.MainApplication.class)
public class BaseACTest {
@Autowired
private WebTestClient webTestClient;
@BeforeAll
public void init1() {
MockitoAnnotations.initMocks(this);
}
@BeforeEach
public void init() {
Assertions.assertNotNull(webTestClient);
}
@Test
public void testGetAllAmenities() {
webTestClient.get().uri("/urltobeplaced/1234")
.header("X-Request-ID", "123")
.header("X-Session-ID", "123")
.header("X-Application-ID", "123")
.exchange()
.expectStatus().isOk();
}
}