gpt4 book ai didi

java - 运行使用 Cucumber 实现 CommandLineRunner 的 SpringBoot 应用程序,在运行功能测试用例之前运行主应用程序

转载 作者:行者123 更新时间:2023-12-01 20:16:14 27 4
gpt4 key购买 nike

我是 Cucumber 和 Spring Boot 的新手,我正在开发一个实现 CommandLineRunner 的 Spring Boot 应用程序,并尝试将其与 Cucumber Framework 集成以运行一些测试并创建相应的报告。现在我的 Cucumber 测试用例运行良好,但在运行测试用例之前它会运行我的 Springboot 应用程序 (Application.java)。这是预期的行为还是只是为了运行我的测试。

主要 Spring Boot 类 - Application.java 类:-

/**
* Main Application Class
*/
@SpringBootApplication
public class Application implements CommandLineRunner {
@Override
public void run(String... args) {
@Autowired
private GWMLController gwmlController;

@Autowired
private SmartXmlController mxMLController;

@Autowired
private ReportingController reportingController;

@Autowired
private ComparisionReportController comparisionReportController;
....
...
My busniess logic
}

现在我的 cucumber 类是:-

  1. AbstractDefination.java

    package cucumberJava.steps;

    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.ActiveProfiles;
    import org.springframework.test.context.junit4.SpringRunner;
    import org.springframework.test.context.web.WebAppConfiguration;

    @RunWith(SpringRunner.class)
    @ActiveProfiles("test")
    @SpringBootTest
    @AutoConfigureMockMvc
    @WebAppConfiguration
    public class AbstractDefinitions{

    public AbstractDefinitions() {
    }

    }
  2. 测试验证:-

    import static junit.framework.TestCase.assertEquals;
    import static junit.framework.TestCase.assertFalse;
    import static junit.framework.TestCase.assertNotNull;

    @ContextConfiguration(classes = {CucumberConfiguration.class})
    public class TestValidations extends AbstractDefinitions {

    @Autowired
    private GWMLController gwmlController;

    @Autowired
    private SmartXmlController mxMLController;

    @Autowired
    private ComparisionReportController comparisionReportController;

    @Given("^GID map is not empty$")
    public void guid_map_is_not_null() throws Throwable {
    comparisonResultMap =
    comparisionReportController.makeComparisionMappingMap
    (comparisonResultMap);
    assertFalse(comparisonResultMap.isEmpty());
    }
  3. CucumberConfiguration.java

    @Configuration
    @ComponentScan(basePackages = "au.com.nab.mx")
    public class CucumberConfiguration {

    }

在我的 build.gradle 中我有:-

 testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-
test', version: '1.5.4.RELEASE'
compile group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
compile group: 'info.cukes', name: 'gherkin', version: '2.12.2'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
}

.功能

功能:Validations.feature

  Scenario Outline: COMPARE_COLUMNS
Given GID map is not empty
When <smt> not-null and <gwml> not null
Then <smt> validateEqual <gwml>

@Smoke
Examples:
| smt | gwml |
| **SMT_GUID | **GWML_GUID |
| SMT_BUY_SELL | GWML_BUY_SELL |

现在我的问题是,每当我运行我的应用程序时,它首先运行我的 Application.java,然后运行我的 Cucumber 测试用例。现在我不确定它的预期行为还是我遗漏了某些内容。

问候,维克拉姆·帕塔尼亚

最佳答案

答案是 - 是的,这是使用 SpringRunner.class 和 @SpringBootTest 和 @ContextConfiguration 注释的预期行为。

关于java - 运行使用 Cucumber 实现 CommandLineRunner 的 SpringBoot 应用程序,在运行功能测试用例之前运行主应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45746913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com