0

I have a testng dependency in pom.xml with 'test' scope:

</dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
            <scope>test</scope>
        </dependency>
</dependencies>

My folder layout is as follows:

src/test/java  - test source folder
src/test/resources - test resources folder

When trying to import testng in classes created under src/test/java/ IntelliJ can not find testng.

SergioLeone
  • 734
  • 1
  • 10
  • 24
  • show us the exception – LazerBanana Jun 26 '17 at 09:22
  • this may help: https://stackoverflow.com/a/28161314/5074444 – Gordon Jun 26 '17 at 09:23
  • I think his source sets are correct. It might be IntelliJ project structure, as far as I remember IntelliJ marks sources differently by default. – LazerBanana Jun 26 '17 at 09:28
  • see here https://stackoverflow.com/questions/174560/sharing-test-code-in-maven#174670 – Mike Adamenko Jun 26 '17 at 09:30
  • @LazerBanana, I'm getting an error from IntelliJ, not exception when running. I.e. enter @Test annotation in my code and the autocomplete only shows JUnit @Test annotation, and TestNG is ommited. If I manually enter `import org.testng.annotations.Test;` then IntelliJ tells - Can not resolve symbol Test. – SergioLeone Jun 26 '17 at 09:31

2 Answers2

1

First of all open Maven Projects tab and simply refresh to get in sync.

Secondly, open the project structure and check if your sources are marked correctly.

Without more info, this is what I would suggest.

LazerBanana
  • 6,865
  • 3
  • 28
  • 47
0

I suspect you have src/test/java in one module/project and you would like to reuse it in other module/project? If that's correct you need to build and install your test jar (add to your source project):

<build>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-jar-plugin</artifactId>
           <version>2.2</version>

           <executions>
               <execution>
                   <goals>
                       <goal>test-jar</goal>
                   </goals>
               </execution>
           </executions>
       </plugin>
    </plugins>
</build>

Then you can use it in other projects by adding maven dependency.

alexey28
  • 5,170
  • 1
  • 20
  • 25