Maven Compilation error [package org.testng.annotations does not exist]

后端 未结 9 1359
陌清茗
陌清茗 2020-12-10 11:09

I\'m pretty new to maven and I want to run my test classes using maven. I have generated the testng.xml and I have created the POM.xml file also. But when you run the

相关标签:
9条回答
  • 2020-12-10 11:38

    Make sure your tests are in "src/test/java". It will solve this problem

    0 讨论(0)
  • 2020-12-10 11:52

    remove test scope testng dependency and add compile

    <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.1.1</version>
            <scope>compile</scope>
        </dependency>
    
    0 讨论(0)
  • 2020-12-10 11:54
    test to compile -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
            <scope>compile</scope>
        </dependency>
    
    0 讨论(0)
  • 2020-12-10 11:55

    Below solution works for me-

    Please add below dependencies in your pom.xml

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.0.0</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>17.0</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-10 11:56

    I've got similar problem. The reason for that was "Scope" option of "testng" dependency set to "test" when "compile" was needed.

    How I fixed it (note, I used Eclipse):

    1. Open pom.xml file.
    2. Go to "Dependencies" tab.
    3. Select "testng" package and click on "Properties..."
    4. On opened screen change "Scope" option to "compile" and click "OK" to save it.
    5. Try to build your project again with "compile test" goals.
    0 讨论(0)
  • 2020-12-10 11:56

    In your pom.xml file you have scope of testng as test

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

    Replace the scope by compile

    <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.13.6</version>
                <scope>compile</scope>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题