Fedorova Daria
Fedorova Daria

Reputation: 1

The import org.testng cannot be resolved with maven

I'm trying to launch TestNG tests with maven, but errors occurs:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:2.0.0:compile (default-compile) on project auto-test.headless.connections: Compilation failure: Compilation failure:
[ERROR] C:\Users\pooor\git\dbeaver-qa-auto\auto-test\headless\connections\src\connections\test\FactoryRunner.java:[3]
[ERROR]         import org.testng.ITest;
[ERROR]                ^^^^^^^^^^

There is no problems with launching in Eclipse or IntelliJIDEA. I've already tried cleaning the .m2 folder and using other versions of testng. Nothing works for me. Here is my pom:

Upvotes: 0

Views: 3312

Answers (1)

jeanpic
jeanpic

Reputation: 541

You seem to be using testng outside test sources, do you import it with the right scope ?

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.4.0</version>
    <scope>compile</scope>  
</dependency>

Although if this class is indeed a test class, you need to follow Maven's standard directory layout and move it in a package under src/test/java. You should then be able to compile with

<scope>test</scope>

Upvotes: 3

Related Questions