无法在 IntelliJ 中找到 TestNG

Unable to find TestNG in IntelliJ

我有一个 Ubuntu Studio 16.10。我有一个 IntelliJ IDEA 2016.3.2 构建 #IC-163.10154.41,构建于 2016 年 12 月 21 日

JRE: 1.8.0_112-release-408-b6 amd64

JVM: OpenJDK 64-Bit JetBrains 的服务器虚拟机 s.r.o 我用 Apache Maven 3.3.9 我在 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>
    <repositories>
        <repository>
            <id>jcenter</id>
            <name>bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>
    <groupId>test</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
     <project.build.sourceencoding>UTF-8</project.build.sourceencoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>

     <build>
         <plugins>
         <plugin>
         <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>

      <version>3.1</version>
      <configuration>
      <source>1.8</source>
            <target>1.8</target>
      </configuration>
     </plugin>

     </plugins>


 </build>


</project>

我去了我的项目目录 运行 mvn clean install 我还检查了另一个 post,其中建议右键单击项目文件夹并选择 Maven-> 重新导入,但该选项不可用。 我得到了 BUILD Success。尽管外部库显示存在 junit。我从未见过 TestNG。在日志中它说..正在下载 testng-6.9.12.jar 当我使用 locate testng-6.9.12.jar 时,我得到的只是一个 return 命令提示符。 在编辑器中,我尝试导入 org.testng.*; import 语句一写完就被删除了。我在 Intellij Ubuntu 16.10 上使用 vim 有点 ar运行gement 我也试过从 jcentral 和 maven 存储库下载但无济于事。

我仅在外部库中看不到 TestNG junitJava 1.8

可能是因为 Maven 在 Maven 中心找不到 6.9.12(因为你的 pom 文件没有任何 <repository> 标签,maven 会尝试只在 [=12] 中寻找你的工件=]).

我尝试搜索它 here 但找不到版本 6.9.12

最新发布的 TestNG 版本是 6.10。因此,请将 <dependency> 中的 <version> 标记替换为 6.10 并重试。那应该会处理它。

<scope>test</scope> 只是告诉 Maven 的一种方便的方式,只有在 运行 测试时才需要解析 TestNG。 compile 的默认范围告诉 TestNG 在编译代码本身时要使工件可用(通常为 src/main/java)。它与您在这里面临的问题没有任何关系(据我所知至少是)