黄瓜测试不会启动Spring启动应用程序

时间:2017-07-15 12:17:42

标签: spring cucumber cucumber-junit

当启动我的Cucumber测试时(通过Selenium和集成/休息),Spring Boot(测试)应用程序不会自动启动。

如何配置Cucumber启动Spring Boot应用程序?

我尝试了很多方法。我的文件是:

黄瓜主要发起人:

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumber_integration_tests")
public class Cucumber_Integration_Test {
}

胶水代码文件类似于:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@IntegrationTest
public class StepDefsIntegrationTest extends SpringIntegrationTest {
    @When("^the client calls /version$")
    public void the_client_issues_GET_version() throws Throwable {
        executeGet("http://localhost:8080/version");
    }
    etc. 
}

在胶水代码文件中启动应用程序的替代方法:

@SpringBootTest( properties = "server.port=8080", classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class wine_Cucumber_Selenium_Steps {
    private WebDriver driver;
    private String baseUrl = "http://localhost";

    private int port = 8080;

    @Given("^I visit the wine cellar home page$")
    public void goToWineCellarHomePage() {
        // Firefox
        // System.setProperty("webdriver.gecko.driver", "K:\\k_schijf\\download_via_firefox\\geckodriver-v0.11.1-win64\\geckodriver.exe");
        // driver = new FirefoxDriver();

        // Chrome
        System.setProperty("webdriver.chrome.driver", "K:\\k_schijf\\download_via_firefox\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        baseUrl += ":" + port;
        driver.navigate().to(baseUrl + "/index.html");
    }

诊断:

  • 我没有看到Spring以消息开头
  • 我收到错误消息" ResourceAccessException:GET请求的I / O错误" http://localhost:8080/version":连接被拒绝"

2 个答案:

答案 0 :(得分:3)

您可能希望将@ContextConfiguration与@SpringBootTest注释一起使用。我有黄瓜测试工作示例here

答案 1 :(得分:2)

感谢 @ravinikam 展示了一个好方向。我将进一步尝试ContextPath和amp;的组合。 SpringBootTest。

答案(可能不是最好的)是我使用了1.2.4版本的Cucumber并将此代码添加到了黄瓜的runTest中。那很有效。

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
@WebIntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
public @interface CucumberStepsDefinition {
}

Bealdung给出了另一个想法:见integration test这个简短的例子。