简体   繁体   中英

Using Surefire to execute TestNG/Selenium tests in a jar

Our project has a suite of Selenium tests that we are currently packaging into a jar with the intent of Jenkins running the tests as a build step. We install the jar into the local repository of a client VM that is configured to have Selenium point back to Jenkins as the host. The trouble we are running into is figuring out a way to get Maven/SureFire to find the Selenium/TestNG tests in the jar we installed. We have a pom with all the dependencies that the tests require on the client, including the jar of tests itself, but when we we run "mvn test" no tests are found. Clearly we are missing something here, any ideas? Thanks.

surefire by default look for file names like Test*.java , *Test.java , *TestCase.java and executes them. if your test doesnt follow any of these pattern then you have to include them explicitly. refer here

Create a main method calling testNG main method and pass your main methods args[] to testNG Main method. Now your test jar will have main method of its to trigger test cases of your desire. You can pass the same paramteres as TestNG to your jar file like testng.xml file or -testClass classapath etc... see example below.

public static void main(String args[])
{
    org.testng.TestNG.main(arg);
}

now you just need to create a xml file of test classes and in jenkins use windows batch command to call your jar file on remote machine with required testNG parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM