selenium
Web集成测试允许对Spring Boot应用程序进行集成测试,而无需进行任何模拟。 通过使用@WebIntegrationTest
和@SpringApplicationConfiguration
我们可以创建加载应用程序并在正常端口上侦听的测试。 Spring Boot的这一小增加使使用Selenium WebDriver创建集成测试变得更加容易。
测试依赖
我们将要测试的应用程序是一个简单的Spring Boot / Thymeleaf应用程序,具有spring-boot-starter-web
, spring-boot-starter-thymeleaf
和spring-boot-starter-actuator
依赖性。 请参阅参考资料以获取GitHub项目的链接。
测试依赖项为:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
<scope>test</scope>
</dependency>
网络集成测试
在经典的Spring Test中,使用MockMvc
可以创建如下的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class HomeControllerClassicTest {
@Autowired
private WebApplicat