【发布时间】:2021-06-29 20:08:49
【问题描述】:
我一直在尝试解决问题,但无法解决。您想分享您对此的看法吗? 我确实添加了 maven-surefire-plugin 插件,但它不起作用,并且由于 pom.xml 我构建的 jenkins 也失败了。
在下面分享我的 pom.xml 和 testng.xml。
- testng.xml
*<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.pages.VisibilityAnnotationDemo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->*
2)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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>VRsessions</groupId>
<artifactId>VRsessions</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>VRsessions</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<testSourceDirectory>src/main/java/com/pages/VisibilityAnnotationDemo</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>VisibilityAnnotationDemo.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
错误日志如下
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project VRsessions: Compilation failure: Compilation failure.
package org.testng does not exist
cannot find symbol
[ERROR] symbol: class Test
[ERROR] location: class com.pages.VisibilityAnnotationDemo
【问题讨论】:
-
请添加编译错误信息。可能这提供了仅此代码 sn-ps 的更多信息。还可以尝试修复您帖子的布局问题,以更清楚地了解您的 sn-ps 中的真正内容。
-
你在添加testng依赖后做了
Maven-> Update project吗? -
@GauthamM 是的,我做到了。
-
@Tejas 是测试源目录
<testSourceDirectory>src/main/java/com/pages/VisibilityAnnotationDemo</testSourceDirectory>正确吗?不应该是test而不是main吗?src/test/java.............. -
@GauthamM...我总是在 src/main 中创建 java 类。它应该在 src/test 文件夹中吗?