Spock / VintageTestEngine-为具有多个测试用例的数据驱动测试方法运行所选测试

主要问题是,当我使用VintageTestEngine时,无法搜索和运行作为数据驱动测试方法一部分的选定测试。

例如,我的测试方法名为Name LoginPageTestSuite_#parameters.TestCaseName随AkeneoLoginPageTestSuite类中的数据一起传递。该测试方法提供了一系列测试数据,因此可以创建具有不同测试数据的多个测试用例。当此测试方法启动时,将创建4个测试用例,每个用例都有一个不同的名称,这是通过将#参数.TestCaseName参数添加到主方法名称而得到的。

VintageTestEngine具有允许您搜索和运行特定测试方法的方法。就我而言,我不希望用4个测试来运行整个程序集,而只运行一个名称为LoginPageTestSuite_TC_003_VerifyingLogin_LoginAndPassword的程序。

我尝试调试VintageTestEngine,如果我在MethodSelectorResolver类(包org.junit.vintage.engine.discovery)中正确理解了该方法,则shouldRun()与我的问题有很大关系。

private static Filter matchMethodDescription (final Description desiredDescription) {
        return new Filter () {
            public boolean shouldRun (Description description) {
                if (! description.isTest ()) {
                    Iterator var2 = description.getchildren (). Iterator ();

                    Description each;
                    up to {
                        if (! var2.hasnext ()) {
                            return false;
                        }

                        each = (Description) var2.next ();
                    } while (! this.shouldRun (each));

                    return true;
                } else {
                    return desiredDescription.equals (description) || this.isParameterizedMethod (description);
                }
            }

在我的情况下,此代码将返回false,因为desireDescription.equals(描述),desireDescription- LoginPageTestSuite_TC_003_VerifyingLogin_LoginAndPassword,说明-LoginPageTestSuite_#参数。TestCaseName

我的Spock测试类和VintageTestEngine类的代码。

package TestSuites.LoginPageTestSuite

import Assertions.LoginPageAsserts
import DataSourceExtensions.TestDataSource
import Model.LoginPageData
import PageObjects.LoginPageObject
import TestSuites.BaseTest
import com.google.common.base.Strings
import org.junit.jupiter.api.DisplayName
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import spock.lang.Shared
import spock.lang.Unroll

class AkeneoLoginPageTestSuite extends BaseTest{

    @TestDataSource(TestsourcePath = "TestSuites/TestCaseData/LoginPageTestCaseData.json")
    private @Shared List<LoginPageData> _testCaseData

    private LoginPageObject _loginPage

    @DisplayName(value = "LoginPageTestSuite_#parameters.TestCaseName")
    @Unroll
    def "LoginPageTestSuite_#parameters.TestCaseName"(LoginPageData parameters)
    {
        given:
        _loginPage = new LoginPageObject()

        when:
        _loginPage.FillusernameAndPassword(parameters.username,parameters.Password)

        then:
        if(!Strings.isnullOrEmpty(parameters.InvalidLoginmessage))
            LoginPageAsserts.VerifyingLoginPageMessageBox(
                    parameters.InvalidLoginmessage,_loginPage.getIncorrectLoginmessageBoxText())

        where:
        parameters << _testCaseData
    }
package Runners

import Configurations.Configuration
import org.junit.platform.engine.EngineDiscoveryRequest
import org.junit.platform.engine.ExecutionRequest
import org.junit.platform.engine.TestDescriptor
import org.junit.platform.engine.UniqueId
import org.junit.platform.engine.discovery.MethodSelector
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder
import org.junit.vintage.engine.VintageTestEngine

class AkeneoRunner {

    static void main(String[] args){
        new Configuration()

        VintageTestEngine engine = new VintageTestEngine()
        EngineDiscoveryRequest discovery = LauncherDiscoveryRequestBuilder.request().selectors(
                new MethodSelector(Class.forName("TestSuites.LoginPageTestSuite.AkeneoLoginPageTestSuite"),"LoginPageTestSuite__TC_003_VerifyingLogin_LoginAndPassword"))
                .build()
        UniqueId root = UniqueId.root("LoginPageTestSuite__TC_003_VerifyingLogin_LoginAndPassword","LoginPageTestSuite__TC_003_VerifyingLogin_LoginAndPassword")

        TestDescriptor testDescriptor = engine.discover(discovery,root)

        engine.execute(new ExecutionRequest(testDescriptor,new NoOpEngineExecutionListener(),new NoConfigurationParameters()))
    }
}

这是我正在使用的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.akeneo.groovy</groupId>
  <artifactId>AkeneoGroovy</artifactId>
  <version>1.0-snAPSHOT</version>

  <name>AkeneoGroovy</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>1.3-groovy-2.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.141.59</version>
    </dependency>
    <dependency>
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <version>1.25</version>
    </dependency>
    <dependency>
      <groupId>com.microsoft.sqlserver</groupId>
      <artifactId>mssql-jdbc</artifactId>
      <version>6.1.0.jre8</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.12.0</version>
    </dependency>
    <dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.6</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.6</version>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-engine</artifactId>
      <version>1.7.0-M1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>RELEASE</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <version>1.7.0-M1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>5.7.0-M1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <pluginmanagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginmanagement>
  </build>
</project>

也许现在更清楚了,如果没有,请告诉我。 谢谢

gdp2009 回答:Spock / VintageTestEngine-为具有多个测试用例的数据驱动测试方法运行所选测试

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2320723.html

大家都在问