Java 具有多个AbstractTestNGSpringContextTests类的Spring引导TestNG
带有多个AbstractTestNGSpringContextTests类的Spring Boot TestNG根据测试类初始化Spring启动上下文 我定义了多个TestNG测试类,如下所示:-Java 具有多个AbstractTestNGSpringContextTests类的Spring引导TestNG,java,spring,spring-mvc,spring-boot,testng,Java,Spring,Spring Mvc,Spring Boot,Testng,带有多个AbstractTestNGSpringContextTests类的Spring Boot TestNG根据测试类初始化Spring启动上下文 我定义了多个TestNG测试类,如下所示:- @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class TestNGClass1 extends AbstractTestNGSpringContextTests{ @
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class TestNGClass1 extends AbstractTestNGSpringContextTests{
@LocalServerPort
public int port;
.......
}
有没有办法在所有这些类中重用Spring上下文 @DirtiesContext测试注释,该注释指示 与测试关联的ApplicationContext是脏的,应该 因此,必须将其关闭并从上下文缓存中删除
@DirtiesContext
并使用@RunWith(SpringRunner.class)和@SpringBootTest
选中此项如何使用@BeforeSuite实现此目标。您能给我一个示例代码段吗?我尝试使用testng套件,而不使用@BeforeSuite检查我的answer@IssamELATIF我正在尝试将现有的应用程序转换为springboot应用程序。如果我使用RunWith annotation,则我得到的端口已被使用。否则,看起来每个testclass都在加载自己的上下文,尽管所有类继承自尝试使用运行集成测试的同一基本classi aamtestng@Vish你能用代码和问题发布你的问题,然后在这篇文章中为我提供评论链接吗。
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class TestNGClass2 extends AbstractTestNGSpringContextTests{
@LocalServerPort
public int port;
.......
}
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class TestNGClass3 extends AbstractTestNGSpringContextTests{
@LocalServerPort
public int port;
.......
}