- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里和其他网站上查看了无数帖子,但没有结果。
我正在尝试针对正在运行的 Spring Boot 应用程序的本地版本运行我的 Cucumber 集成测试,作为 CI 管道的一部分。我不断收到“连接被拒绝”的消息,这会让您相信该应用程序没有启动,但是,如果我尝试使用测试处于断点时提供的端口正常启动我的应用程序,它会告诉我这一点端口已被使用。
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.busybee</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backend</name>
<description>Busy Bees backend API</description>
<properties>
<java.version>1.8</java.version>
<cucumber-version>1.2.5</cucumber-version>
<unit-tests.skip>false</unit-tests.skip>
<integration-tests.skip>false</integration-tests.skip>
</properties>
<profiles>
<!-- The Configuration of the unit profile. This is the default profile -->
<profile>
<id>unit-test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>unit-test</build.profile.id>
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
<!-- The Configuration of the integration-test profile -->
<profile>
<id>integration-test</id>
<properties>
<build.profile.id>integration-test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Run *Test.java tests as unit tests during test phase -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
<!-- Run *IT.java tests as integration tests during verify phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
后端应用
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
@EnableJpaRepositories
public class BackendApplication {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
public static void main(String[] args) {
final SpringApplication springApplication =
new SpringApplication(BackendApplication.class);
// it is being added here for LOCAL run ONLY , spring profiles should be be run time parameters when run spring boot jar
springApplication.setDefaultProperties(Collections.singletonMap("spring.profiles.default","LOCAL"));
springApplication.addListeners(new ApplicationPidFileWriter());
springApplication.run(args);
}
}
步骤定义
public class GetNodeSteps extends CucumberBase {
ResponseEntity<Location> responseLoc;
@Before("@BeforeCreateLocation")
public void create_existing_location() throws Throwable {
Location location = generateLocation();
responseLoc = template.postForEntity("/location/register", location, Location.class);
if (responseLoc.getStatusCodeValue() == HttpStatus.BAD_REQUEST.value()) {
fail("Couldn't create location");
}
}
//Rest of steps omitted
cucumber 基地
@SpringBootTest(classes = BackendApplication.class, webEnvironment = RANDOM_PORT)
@ContextConfiguration
public class CucumberBase {
@Autowired
public TestRestTemplate template;
@LocalServerPort
public int randomServerPort;
@Before
public void contextLoads() throws Exception {
}
}
功能IT
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features", glue = {"com.busybee.backend.integration"})
public class FeaturesIT {
}
堆栈跟踪
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.4.RELEASE)
2020-05-27 17:49:49.787 INFO 20488 --- [ main] c.b.backend.integration.GetNodeSteps : Starting GetNodeSteps on Rob-Desktop with PID 20488 (started by Robert in C:\dir)
2020-05-27 17:49:49.791 INFO 20488 --- [ main] c.b.backend.integration.GetNodeSteps : The following profiles are active: test
2020-05-27 17:49:50.630 INFO 20488 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-27 17:49:50.694 INFO 20488 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 56ms. Found 4 JPA repository interfaces.
2020-05-27 17:49:51.183 INFO 20488 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-27 17:49:51.757 INFO 20488 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 0 (http)
2020-05-27 17:49:51.765 INFO 20488 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-27 17:49:51.766 INFO 20488 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-05-27 17:49:51.882 INFO 20488 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-27 17:49:51.882 INFO 20488 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2037 ms
2020-05-27 17:49:52.110 INFO 20488 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-27 17:49:52.184 INFO 20488 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
2020-05-27 17:49:52.323 INFO 20488 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-27 17:49:52.449 INFO 20488 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-27 17:49:52.601 INFO 20488 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-27 17:49:52.626 INFO 20488 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-05-27 17:49:53.369 INFO 20488 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-27 17:49:53.375 INFO 20488 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-27 17:49:53.967 WARN 20488 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-05-27 17:49:54.199 INFO 20488 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2020-05-27 17:49:54.391 INFO 20488 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-27 17:49:54.439 INFO 20488 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2020-05-27 17:49:54.728 INFO 20488 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2020-05-27 17:49:54.749 INFO 20488 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2020-05-27 17:49:54.774 INFO 20488 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2020-05-27 17:49:54.982 INFO 20488 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 58500 (http) with context path ''
2020-05-27 17:49:54.985 INFO 20488 --- [ main] c.b.backend.integration.GetNodeSteps : Started GetNodeSteps in 5.609 seconds (JVM running for 6.852)
Step failed
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:58500/location/register": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:452)
at org.springframework.boot.test.web.client.TestRestTemplate.postForEntity(TestRestTemplate.java:457)
at com.busybee.backend.integration.GetNodeSteps.create_existing_location(GetNodeSteps.java:48)
感谢您提供的任何帮助,谢谢。
最佳答案
我设法弄清楚,我的 H2 数据库不是由 SpringBootTestApplication 创建的,因为我的测试属性是这样的:
spring.jpa.hibernate.ddl-auto=update
何时需要:
spring.jpa.hibernate.ddl-auto=create
关于java - 使用 Spring Boot 进行 Cucumber 集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62048491/
虽然我经常来这里寻求解决方案,但这是我的第一篇文章! 问题: 尝试运行“railsgeneratecucumber:install”时我收到错误:找不到生成器 cucumber :安装 注意:在 Wi
希望我可以清楚地解释我的问题,以使其他人可以理解,在这里,假设我有以下两种假设情况: Scenario: Filter sweets by king size and nut content Give
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 7 年前。 Improv
我在下面的 cucumber 项目中设置了 cucumber 选项: 我通过 mvn 命令行使用 -Dcucumber.options 运行测试来覆盖我的项目的选项: mvn -f "pom.xml"
我试图运行一个简单的Feature文件,但是却遇到了Exception这样的异常: 线程“主” cucumber.runtime.CucumberException中的异常:解析功能文件时出错。 这是
我只是在学习 Cucumber 并注意到如果两个完全独立的特征有两个步骤不小心措辞相同,Cucumber 只为它们建议一个步骤定义。这是否意味着步骤定义是全局的并且它们是要共享的? 例子 假设一个业务
我正在尝试配置 FactoryGirl 以使用我的 Cucumber 测试。 我在 env.rb 中添加了以下几行 require 'factory_girl' Dir.glob(File.join(
有没有办法为 Cucumber 中的某个功能定义所有场景的清理步骤?我知道Background用于定义其后的每个场景的设置步骤,但是有没有办法定义在每个场景结束时发生的类似事情? 最佳答案 您可以在
Cucumber-jvm javadocs指出胶水元素的目的是指定stepdefinitions和hook的位置。但是,这似乎对我不起作用。可以说我在目录a中有我的功能,在步骤b中有我的步骤定义。然后
我必须测试一个消息路由应用程序,其功能大致如下:- 消息发送到应用程序- 应用程序检查消息- 根据消息内容,消息被转发到某处 绝大多数测试用例几乎相同;生成特定类型的消息,将其加载到系统中,等待几秒钟
在进行 BDD 时,Cucumber 似乎是指定行为的默认工具,但是 Cucumber 网站和文章看起来有点过时,而且不太活跃。 有哪些替代方案? 最佳答案 一个非常好的库,具有 Eclipse 的高
我有一个Cucumber表中,其中一个字段是一个日期,我想用今天的日期填充该日期。有没有一种方法可以做到这一点,而不必将今天的日期硬编码到表中? 基本上我想在表中输入Time.now.strftime
我有一个步骤定义,我希望其中有一个可选参数。我相信两次调用此步骤的示例比其他任何内容都更好地解释了我所追求的内容。 I check the favorite color count I check t
我在不同环境中执行 cucumber-jvm 场景时遇到问题。包含在场景特征文件中的数据属于一个环境。为了在不同的环境中执行场景,我需要根据要执行的环境更新特征文件中的数据。 例如,在以下场景中,我将
我有一个 cucumber 项目,我想获得项目中的所有标签,以便能够选择它们作为参数。 我找到了这个 question cucumber 可以选择获取标签,但我发现它不再起作用,然后我发现了另一个 q
@@file_name Feature: Addition 为了避免愚蠢的错误 作为一个数学白痴 我想被告知两个数字的总和 场景:两个数字相加 Given I have entered @number
Java v8.x - spring v5.x cucumber v4.2.0 我试过 temyers/cucumber-jvm-parallel-plugin 并且工作正常,但是当我进入他们的 gi
目前,尝试通过命令行窗口运行测试时,以下命令可以工作,但是自从从 info.cakes 更新到 io.cucumber 后,它似乎不再工作了? mvn test -Dcucumber.options=
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 4 年前。 Improve
如何使用 java 从我的功能中定义“我想要”步骤? 我的 cucumber 项目设置如下: 登录功能 Feature: User Login I want to test on "www.g
我是一名优秀的程序员,十分优秀!