当前位置: 首页 > 知识库问答 >
问题:

Maven测试或mvn清洁安装测试不起作用。它只显示“构建成功”

公羊新
2023-03-14

我陷入了这个问题。我正试图用maven测试这个项目。我输入了“mvn测试”、“mvn测试编译”、“mvn包”等等。还要多次尝试清理项目,重新安装maven/intellij和testng,还要尝试更改testng。xml目录。但它总是显示如下相同的输出:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< {{ProjectName}}:Automation >--------------------------
[INFO] Building {{ProjectName}}Automation 0.0.1-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.113 s
[INFO] Finished at: 2022-03-16T17:30:56+02:00
[INFO] ------------------------------------------------------------------------

我的POM是:

<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>SomeGroup</groupId>
  <artifactId>Automation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <includes>
                        <include>**/Test*.java</include>
                        <include>**/*Test.java</include>
                        <include>**/*TestCase.java</include>
                    </includes>
                    <suiteXmlFiles>
                        <suiteFile>src/tests/resources/suites/testng.xml</suiteFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>true</testFailureIgnore>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    </configuration>
            </plugin>
        </plugins>
    </build>
    <packaging>pom</packaging>

  <name>SomeName</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <suiteXmlFile>src/tests/resources/suites/testng.xml</suiteXmlFile>
  </properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.5.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.22</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.12.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>com.amihaiemil.web</groupId>
        <artifactId>eo-yaml</artifactId>
        <version>6.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.30</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>4.4.3</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-testng-adapter</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.2</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.aerogear</groupId>
        <artifactId>aerogear-otp-java</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>5.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts-core</artifactId>
        <version>1.3.8</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains</groupId>
        <artifactId>annotations</artifactId>
        <version>23.0.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>20041127.091804</version>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.21.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
</project>

我的testng.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Web Automation">
<!--    <parameter name="env" value="${env}"/>-->
<!--    <parameter name="browser" value="${browser}" />-->
    <parameter name="env" value="test"/>
    <parameter name="browser" value="chrome"/>
    <test name="patientTests" >
        <packages>
            <package name="FunctionalTests"/>
        </packages>
    </test>
</suite>

结构是:

项目结构

如果有人帮我,我会很高兴...一切都从“类路径错误”开始,事情出错了

我的测试用例如下所示:

    package FunctionalTests;

import org.testng.Assert;
import org.testng.annotations.Test;


import java.io.IOException;

    public class LoginTest extends BaseTest{
    
        @Test(groups = {"fullRegression","LoginTests", "PERRY-269", "sanityCheck"},
                description = "Login as Provider with valid email")
        public void loginAsProviderWithEmail() throws IOException {
            logINFO("Enter email and password and click login.");
            loginPage.loginWithEmail(providerEmail, providerPassword);
            Assert.assertTrue(checkHttpResponseCode());
    
            logINFO("Check if home page loaded (Top bar tracker button exists).");
            Assert.assertTrue(providerHomePage.isPageLoaded(), "Home page not loaded.");
        }

我的基本测试是这样的:

@Listeners(Utils.Listeners.TestListener.class)
public class BaseTest {

    LoginPage loginPage;

    private static final String envYamlFilePath = "src/tests/resources/config/env.yml";
   // public YamlReader environmentsYamlReader;
    public static YamlReader environmentsYamlReader = new YamlReader(envYamlFilePath);

    static final SoftAssert softAssert = new SoftAssert();


    private static String providerEmailPath;
    private static String providerPasswordPath;
    private static String envPath;

    static String providerEmail;
    static String providerPassword;
    static String url;

    public RemoteWebDriver driver;

    public WebDriverController instance;
    public String WEBDRIVER = "driver";


    @BeforeSuite
    public void setUpSuite(ITestContext context) {
        String browser = context.getCurrentXmlTest().getParameter("browser");
        String env = context.getCurrentXmlTest().getParameter("env");

        if (browser == null) browser = defaultBrowser;
        if (env == null) env = defaultEnvironment;

        envPath = env + ".url";
        providerEmailPath = env + ".providerEmail";
        providerPasswordPath = env + ".providerPassword";

        url = environmentsYamlReader.read(envPath).get().toString();
        providerEmail = environmentsYamlReader.read(providerEmailPath).get().toString();
        providerPassword = environmentsYamlReader.read(providerPasswordPath).get().toString();
       

    @BeforeMethod
    public void setUpMethod(ITestContext context, ITestResult testResult) {
        String browser = context.getCurrentXmlTest().getParameter("browser");
        String env = context.getCurrentXmlTest().getParameter("env");

        instance = new WebDriverController();

        if (browser == null) browser = defaultBrowser;
        if (env == null) env = defaultEnvironment;

        driver = (RemoteWebDriver)instance.start(browser);
        testResult.setAttribute(WEBDRIVER, driver);

        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        driver.get(url);

        loginPage = new LoginPage(driver);
        
    }

    @AfterMethod
    public void cleanupBrowser(ITestResult testResult) {
        RemoteWebDriver driver = driver(testResult);
        driver.quit();
    }

共有1个答案

南宫炜
2023-03-14

POMtestng。xml只是设置文件

您必须有一个带有test注释的测试方法。此外,一些代码正在运行,最后是一个基本的断言代码。

[Test]
public void Test1() {

  // Test code goes here
     Assert.true(boolVal, "Testing that boolVal is true");

}

确保您的代码使用实际的测试步骤和案例创建测试套件。

 类似资料:
  • 我陷入了这个问题。我正试图用maven测试这个项目。我输入了“mvn测试”、“mvn测试编译”、“mvn包”等等。还要多次尝试清理项目,重新安装maven/intellij和testng,还要尝试更改testng。xml目录。但它总是显示如下相同的输出: 我的POM是: 我的testng.xml是: 结构是: 项目结构 如果有人帮我,我会很高兴...一切都从“类路径错误”开始,事情出错了

  • 关于Maven的小问题,以及安装和站点之间的区别。 当运行一个非常基本的干净安装时,我可以看到单元测试运行良好,完全没有问题。 然后,我得到了为项目生成一个网站的要求,以放置测试报告、javadoc等... 因此,我只是在maven生命周期中更进一步,使用mvn clean site而不是mvn Clear install。 然而,令人惊讶的是,mvn干净的网站似乎没有运行测试用例。(与 mvn

  • 和之间到底有什么区别?当我运行这两个命令时,它们似乎都在做同样的事情。

  • 我是学习java编程的新手!我想在maven项目中制作一个。jar。在运行此命令后,我将得到以下错误消息:

  • 我正在使用Tycho插件来编译一个Eclipse插件项目。当我运行命令时 我的生成通行证 我的生成失败,原因如下: 失败stacktrace为: 从我在Maven上可以找到的所有东西来看,调用阶段应该隐式地触发阶段。这是怎么回事?

  • 我有一个用selenium进行单元测试和集成测试的项目。 当我用IntelliJ执行cucumber集成测试时,它工作得很好,您可以看到: 用Intellij执行cucumber集成测试 但是,当我执行mvn集成测试时,似乎没有发现任何联调: 故障保护输出 我定义了以下POM: > 文件夹结构是文件夹结构 mvn集成-测试输出https://drive . Google . com/file/d/