Domanda

I'm trying to run a testing suite using XML and TestNG, but I'm always getting the same message using both: Eclipse and the command line:

[TestNG] Running:
  /Users/achavez/Programs/Selenium/java/src/tests/resources/testng.xml


===============================================
TestingSuite1
Total tests run: 0, Failures: 0, Skips: 0
===============================================

The file is read correctly, but it seems like the tests are not running.

These are the contents of my testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestingSuite1" verbose="1">
    <test name="Test1"  >
        <packages>
            <package name="tests"/>
        </packages>
    </test>
</suite>

and this is how my directory structure looks like in Eclipse:

TestNG Directory Structure in Eclipse

Also, this is also how I'm attempting to run the testing suite through the command line:

java -jar /Applications/Zend\ Studio.app/Contents/Resources/Java/plugins/org.testng.eclipse_6.8.6.20141201_2240/lib/testng.jar src/tests/resources/testng.xml

I've tried cleaning the project through eclipse, and that didn't seem to help. I also tried running:

mvn clean but it didn't do the job either.

Any help pointing me to the right direction will be greatly appreciated!

È stato utile?

Soluzione

You could also check imports for imported Test annotation, should be:

import org.testng.annotations.Test;
@Test
public myTest(){ ... }

and not for example:

import org.junit.Test;

Altri suggerimenti

I had to change my method access modifier to public from private to get it working .

Apparently, TestNG is wrong regarding generating the XML file for the testing suite.

Even though following their instructions to the letter, my tests were not running. I ended up with this testng.xml file and my tests, started to run:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestingSuite" parallel="none">
  <test name="Test1">
    <classes>
      <class name="tests.Page1"/>
    </classes>
  </test>
    <test name="Test 2">
        <classes>
            <class name="tests.Page2"/>
        </classes>
    </test>
</suite>

I experienced a similar issue and it was resolved by performing a project clean within Eclipse (Project-> Clean-> Clean Selected project)

In my case, the @Test annotation was imported automatically by IDE as import org.junit.Test.

After changing it to import org.testng.annotations.Test the tests got picked up correctly.

Very simple but sometimes hard to spot. @Test is not picked when no data is returned by the corresponding dataprovider.

There were two problems in the code:
1. This was because, my @Test method was calling another method which will return a Boolean. Once I commented the same @Test and the method, the whole testNG xml started working.
2. Second mistake was , I was using the below ,that was a wrong assignment of Poi Classes. Workbook WB = new XSSFWorkbook(FIS); Sheet WSh= WB.getSheetAt(1); I changed the above to below: XSSFWorkbook WB = new XSSFWorkbook(FIS); XSSFSheet WSh= WB.getSheetAt(1); After both of those above corrections, the script started working.

In my case, the test was accidentally marked as "enabled = false" inside the @Test(...). Make sure the value for you is marked as "true".

I also had this problem, and none of the above solutions worked. Restarting Eclipse, however, did. I know this seems like an unnecessary answer, but I myself would have saved a lot of time if I had done it sooner, so I'll post it anyway.

I had the same problem and here is my results: In my project I had test file in

src/test/java/com/temporary/core

and in the same time I had resources for the test in

src/test/resources/com/temporary/Core

As I found, testng tried to find test file in the second directory.

When I renamed directory with resources from Core to tcore, the problem was fixed.

I had this same issue, here is what worked for me:

  1. I put all of the TestNG libraries in a separate lib folder in my project

    a. com.beust.jcommander_1.72.0.jar

    b. org.apache-extras.beanshell.bsh_2.0.0.b6.jar

    c. org.testng_6.14.2.r201802161450.jar

    d. or.yaml.snakeyaml_1.17.0.jar

  2. I also put a copy of selenium-server and chromedriver in the lib folder as well

  3. From my project folder (with testng.xml located in the project root) I ran:

    java -cp .\lib\*;.\target\classes org.testng.TestNG testng.xml

I was facing the same issue , i have updated/installed TestNG from eclipse marketplace it worked for me

if the @Test method is public boolean() with return type as true/flase it doesnot execute.. strange but worked in my-case.

I had done all possible solution that everyone shared here and still does not work.

Heard someone mentioned creating a new workspace.

So I started a new workspace and recreated the whole TestNG suite & methods.

It worked!

Most probably my other TestNg stuff in my previous workspace could have conflicted with the recent Testng setup.

So starting a new workspace solved!

This can also happen when there is groups usage in suite.xml and @BeforeXXX annotations have missing alwaysRun = true.

@BeforeTest(alwaysRun = true)
public void setUp() throws IOException {
}

In my case I was using JUnit and then moved to testNG, so besides updating the imports in the classes:

import org.testng.annotations.Test;
@Test
public myTest(){ ... }

I also had to remove the dependency of JUnit from my pom.xml. Otherwise maven-surefire-plugin automatically tries to run using JUnit. So you can either remove or specify a provider as mentioned here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top