当前位置: 首页 > news >正文

网站建设电话销售不被挂断网站建设移动网络

网站建设电话销售不被挂断,网站建设移动网络,tv网站建设,直播app开发价格Web集成测试允许对Spring Boot应用程序进行集成测试#xff0c;而无需进行任何模拟。 通过使用WebIntegrationTest和SpringApplicationConfiguration我们可以创建加载应用程序并在普通端口上侦听的测试。 Spring Boot的这一小增加使使用Selenium WebDriver创建集成测试变得更加… 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项目的链接。 测试依赖项为 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope /dependency dependencygroupIdorg.assertj/groupIdartifactIdassertj-core/artifactIdversion1.5.0/versionscopetest/scope /dependency dependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion2.45.0/versionscopetest/scope /dependency网络集成测试 在经典的Spring Test中使用MockMvc可以创建如下的测试 RunWith(SpringJUnit4ClassRunner.class) SpringApplicationConfiguration(classes Application.class) WebAppConfiguration public class HomeControllerClassicTest {Autowiredprivate WebApplicationContext wac;private MockMvc mockMvc;Beforepublic void setUp() throws Exception {mockMvc MockMvcBuilders.webAppContextSetup(wac).build();}Testpublic void verifiesHomePageLoads() throws Exception {mockMvc.perform(MockMvcRequestBuilders.get(/)).andExpect(MockMvcResultMatchers.status().isOk());} } SpringApplicationConfiguration扩展了ContextConfiguration功能并加载应用程序上下文以进行集成测试。 要创建没有WebIntegrationTest环境的测试我们应该使用WebIntegrationTest批注定义测试 RunWith(SpringJUnit4ClassRunner.class) SpringApplicationConfiguration(classes Application.class) WebIntegrationTest(value server.port9000) public class HomeControllerTest {} 这将在JUnit测试中启动完整的应用程序监听端口9000 。 有了这样的测试我们可以轻松地使用浏览器添加Selenium并执行实际的功能测试除非使用HtmlUnit驱动程序否则在无头环境中将无法工作–但这不在本文的讨论范围之内。 添加硒 将Selenium添加到测试中非常简单但是我想实现的目标还不止于此因此我创建了一个自定义批注将我的测试标记为Selenium测试。 我还以允许将WebDriver注入测试实例的方式配置了它 RunWith(SpringJUnit4ClassRunner.class) SpringApplicationConfiguration(classes Application.class) WebIntegrationTest(value server.port9000) SeleniumTest(driver ChromeDriver.class, baseUrl http://localhost:9000) public class HomeControllerTest {Autowiredprivate WebDriver driver;} SeleniumTest是一个自定义注释 Documented Inherited Retention(RetentionPolicy.RUNTIME) Target(ElementType.TYPE) TestExecutionListeners(listeners SeleniumTestExecutionListener.class,mergeMode MERGE_WITH_DEFAULTS) public interface SeleniumTest {Class? extends WebDriver driver() default FirefoxDriver.class;String baseUrl() default http://localhost:8080; } 注释使用添加了测试执行侦听器该侦听器将创建可在集成测试中使用的WebDriver实例。 TestExecutionListener定义了一个侦听器API用于对测试执行事件做出反应。 它可以用于测试。 例如Spring Test中的示例实现用于支持测试管理的事务或将依赖项注入到测试实例中。 TestExecutionListener 注意为了更好的可读性 SeleniumTestExecutionListener的代码的某些部分被跳过。 SeleniumTestExecutionListener提供了将配置的WebDriver注入测试实例的方法。 该驱动程序实例仅创建一次并且可以使用SeleniumTest批注简单地更改所使用的驱动程序。 最重要的是在Bean Factory中注册驱动程序。 Override public void prepareTestInstance(TestContext testContext) throws Exception {ApplicationContext context testContext.getApplicationContext();if (context instanceof ConfigurableApplicationContext) {SeleniumTest annotation findAnnotation(testContext.getTestClass(), SeleniumTest.class);webDriver BeanUtils.instantiate(annotation.driver());// register the bean with bean factory} } 在使用WebDriver打开应用程序的每个测试方法的基本URL之前请执行以下操作 Override public void beforeTestMethod(TestContext testContext) throws Exception {SeleniumTest annotation findAnnotation(testContext.getTestClass(), SeleniumTest.class);webDriver.get(annotation.baseUrl());} 另外在每次失败时都会生成一个屏幕截图 Override public void afterTestMethod(TestContext testContext) throws Exception {if (testContext.getTestException() null) {return;}File screenshot ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);// do stuff with the screenshot} 每次测试后驱动程序将关闭 Override public void afterTestClass(TestContext testContext) throws Exception {if (webDriver ! null) {webDriver.quit();} } 这只是一个例子。 实现非常简单。 我们可以扩展注释和侦听器的功能。 考试 运行以下测试将启动Chrome浏览器并使用Selenium执行一些简单的检查 RunWith(SpringJUnit4ClassRunner.class) SpringApplicationConfiguration(classes Application.class) WebIntegrationTest(value server.port9000) SeleniumTest(driver ChromeDriver.class, baseUrl http://localhost:9000) public class HomeControllerTest {Autowiredprivate WebDriver driver;private HomePage homePage;Beforepublic void setUp() throws Exception {homePage PageFactory.initElements(driver, HomePage.class);}Testpublic void containsActuatorLinks() {homePage.assertThat().hasActuatorLink(autoconfig, beans, configprops, dump, env, health, info, metrics, mappings, trace).hasNoActuatorLink(shutdown);}Testpublic void failingTest() {homePage.assertThat().hasNoActuatorLink(autoconfig);} } 该测试使用带有自定义AssertJ断言的简单页面对象。 您可以在GitHub中找到完整的源代码。 请参阅参考资料。 如果发生故障驱动程序拍摄的屏幕快照将存储在适当的目录中。 摘要 WebIntegrationTest和SpringApplicationConfiguration批注可以在常规JUnit测试中对完全加载的Spring Boot应用程序进行集成测试。 使应用程序在测试中运行将为您提供使用Selenium并使用浏览器运行功能测试的可能性。 如果将其与Profile和Spring Test的其他功能例如Sql SqlConfig Sql SqlConfig可能会为集成测试提供功能强大而简单的解决方案。 参考文献 源代码 https : //github.com/kolorobot/spring-boot-thymeleaf Spring Boot测试 http : //docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-testing Spring测试 http //docs.spring.io/spring/docs/current/spring-framework-reference/html/testing.html 翻译自: https://www.javacodegeeks.com/2015/03/spring-boot-integration-testing-with-selenium.html
http://wiki.neutronadmin.com/news/404906/

相关文章:

  • 微网站如何做微信支付宝支付宝支付接口打开网站是iis7
  • 南县做网站推荐网站开发项目思路
  • 百度容易收录的网站网站推广多少钱
  • 网站建设什么是静态网页热门搜索关键词
  • 一站式服务大厅官网在线设计装修的网站
  • 宁波网站制作设计凡科送审平台学生端
  • 免费素材下载网站y1s华硕wordpress
  • 静态网站seo怎么做上海医疗网站备案
  • 通辽做家教的网站做纸巾定制的网站
  • 做响应式网站的常用尺寸手机网络不稳定
  • wordpress 下单长沙seo 优化选智投未来no1
  • 如何在网站上显示百度权重推广app的单子都在哪里接的
  • 做网站要几天网站服务器一个多少钱
  • 惠东做网站公司wordpress去掉边栏
  • 17网站一起做网店增城百度视频推广怎么收费
  • 动态型网站建设重庆广告公司
  • 大型门户网站建设所具有的功能模块主要有几种类型邢台网警
  • 网站开发包括哪些工作沈阳市营商环境建设监督局网站
  • 苏华建设集团有限公司网站一键生成ppt的软件
  • 济宁市住房和城乡建设局网站wordpress 2.6
  • 怎么把别人网站模板下载出来智能建造平台
  • 深圳电商网站制作网站后台无法访问
  • 个人网站趋向个人网站可以备案几个
  • 网站主目录权限配置河北邯郸市简介
  • 十堰建设网站网站建设有哪些特点
  • 中小学教师兼职做网站网站收录了怎么做排名
  • 做外贸在哪个平台比较好烟台seo
  • 建网站哪家划算帮助中心网站源码
  • 网站开发公司成都建设项目环境影响网站
  • 视频网站前台怎么做wordpress 阅读小说