2017-08-11 140 views
0

我正在學習使用java將Intellij作爲IDE和maven作爲程序包管理器的java測試。無法解析Intellij IDEA中的符號錯誤

我的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>depositTest</groupId> 
    <artifactId>deposittest</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <!-- https://mvnrepository.com/artifact/junit/junit --> 
     <!-- https://mvnrepository.com/artifact/junit/junit --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 

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

     <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.53.0</version> 
     </dependency> 


    </dependencies> 
</project> 

我的import語句如下:

import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 
import org.testng.annotations.AfterTest; 
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.By; 
import static org.junit.Assert.*; 
import static org.testng.AssertJUnit.assertEquals; 
import org.openqa.selenium.WebDriver; 

不過,我得到can not resolve symbol errors在IDE TestNG的和JUnit庫。我究竟做錯了什麼?

+0

您是否嘗試在Maven側欄中導入選項? –

+0

將其設置爲自動導入並重新導入數次。 –

+0

請參閱http://stackoverflow.com/a/42427510/104891。確保它可以在IntelliJ IDEA之外的命令行上運行。 – CrazyCoder

回答

0

您在<dependency>部分中指定了<scope>test</scope>部分,用於JUnitTestNG

所以這些庫只能用於src/test/java

請檢查您是否在指src/main/java中的這些類。

的IntelliJ不會解決了JUnit和TestNG班src/main/java

解決您的問題,請您<dependency>兩個TestNG的和JUnit刪除<scope>標籤,然後再試一次。

相關問題