Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not import testng when scope is marked 'test' in maven pom.xml #1458

Closed
2 of 7 tasks
serpro69 opened this issue Jun 26, 2017 · 10 comments
Closed
2 of 7 tasks

Can not import testng when scope is marked 'test' in maven pom.xml #1458

serpro69 opened this issue Jun 26, 2017 · 10 comments

Comments

@serpro69
Copy link

TestNG Version

6.11

Expected behavior

Actual behavior

I've marked testng dependency scope as 'test'
Trying to import testng annotations from test folder, however import org.testng.annotations.Test; gets marked as error - Can not resolve symbol 'Test'

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

testng dependency in pom.xml

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

folders layout:

src/test/java  - java test folder
src/test/resources - test resources folder
@juherr
Copy link
Member

juherr commented Jun 26, 2017

Hi,

It looks you have a problem with maven or your IDE.
I've no idea how we are supposed to fix it.

Maybe you can share your project which will help us to reproduce the issue.

@missedone
Copy link
Contributor

You can check if maven download the testng jar success in the local maven repo: $HOME/.m2/repository/org/testng/testng/6.11/
If the file is currpt , remove it , maven build again.

@serpro69
Copy link
Author

serpro69 commented Jun 26, 2017

@juherr
I think you are correct, seems like IntelliJ bug. I can run an mvn clean verify command and tests are executed successfully, however I still can not import testng classes in my tests and IntelliJ gives me errors when I import and testng classes are not visible in autocomplete as well.

You can find a simple sample here: https://github.com/jedi-tester/test

Basically everything seems to be working when running tests from console with maven. However I can not run tests from IDE because IntelliJ does not see testng classes. Only if I remove 'test' scope from testng dependency in pom.xml then everything seems to be working as expected

@ghost
Copy link

ghost commented Jun 26, 2017

This is more an issue with IntelliJ than TestNG. Same code works well with NetBeans / Eclipse.

@juherr
Copy link
Member

juherr commented Jun 26, 2017

@elishaebenezer Thanks for the feedback! Do you reproduce the issue on intellij too?

@juherr
Copy link
Member

juherr commented Jun 26, 2017

Same question on O: https://stackoverflow.com/questions/44756498/importing-testng-classes-when-scope-marked-test

BTW, you should post an issue on IDEA bugtracker: https://youtrack.jetbrains.com/issues

@juherr juherr closed this as completed Jun 26, 2017
@madhu4mobile
Copy link

Try changing the scope as compile.
compile

@teju8
Copy link

teju8 commented Mar 8, 2021

@juherr This is a bit unrelated to this question, but I have few classes like dataproviders in 'src/main/java' and maven is explicitly throwing error for not being able to detect the testNG annotations for classes of 'src/main/java'. Can you tell me how to fix that?

@juherr
Copy link
Member

juherr commented Mar 8, 2021

@teju8 It is related to the maven runner and it will be difficult to investigate without more context. BTW, you should ask your question on StackOverflow with the maven-surefire-plugin tag maybe @Tibor17 will be able to answer you there.

@dxmano1985
Copy link

dxmano1985 commented Aug 26, 2023

@juherr This is a bit unrelated to this question, but I have few classes like dataproviders in 'src/main/java' and maven is explicitly throwing error for not being able to detect the testNG annotations for classes of 'src/main/java'. Can you tell me how to fix that?

Hi, I understand that this issue posted in 2021 and I have read this since I faced the same issues. Hope you found the solution already. The reason in my case is in pom.xml for testng dependency was set to 'test'. The value 'test' limits the dependency to use it under src/test/java/. If I remove the or set it to 'compile' then I am able to import testng classes under src/main/java. Maven explains about dependency and scope here https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

<dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
      <version>7.8.0</version>
      <scope>test</scope>
</dependency>

Hope this helps someone! Cheers!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants