I am trying to run testng.xml from command prompt and getting error that main class not found.
How to give reference of org.testng.jar while running testng.xml from command prompt
Have you tried reading documentation?
Assuming that you have TestNG in your class path, the simplest way to invoke TestNG is as follows:
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
If you have your tests and testng.jar in your CLASSPATH the above command should be enough.
Approximate syntax for more complex scenarios:
java -cp "/path/to/test.jar;/path/to/your/tests.jar;/path/to/test/dependencies.jar" org.testng.TestNG testng.xml
where testng.xml is the TestNG config file
More information with examples: Automated test using TestNG chapter
Related
How can I run testng.xml file in linux with cmd ?
What is command to run in linux command
java -cp "path to the testng jar" org.testng.TestNG testng.xml
For testng you need only one jar.So put that in the classpath and for the compiler to understand that it was a testng xml file you have to add "org.testng.TestNG" and run like a normal java program.
The testNG jar file can found in this link if you didn't have the jar file
-> You have to remember one thing,The compiled class file must be in the same directory you are running from the test suite xml
cd <Location of TestNGProject> ie. D:\workspace2\TestNG java -cp
D:\workspace2\TestNG\lib\*;D:\workspace2\TestNG\bin org.testng.TestNG testng.xml
java -cp argument is used to provide path to classes and libraries that our program need to run
TestNG+Maven, I have a framework where a block of code generates the testNG.xml on runtime, so my problem is that when I execute the command - mvn test, it starts looking for the TestNG file which is still not there because the code to generate that TestNG.xml is yet not executed.
So I want to know an approach where whenever I execute mvn test, system should first execute a block of code (I already have that code which generates the TestNG.xml file) and pom.xml should pick the newly generated xml file and start running the test cases from newly generated testNG.xml.
You just need to create a .bat or .sh file.
using these batch files you can trigger your first code and once it will complete the mvn command will be triggered.
below are some links which can help you to create a batch or sh file
https://fossbytes.com/what-is-a-batch-file-in-windows-how-to-create-a-batch-file/
https://askubuntu.com/questions/223691/how-do-i-create-a-script-file-for-terminal-commands/223698
Hope it will help you :)
I know how to configure Jenkins to run a particular test class using mvn -Dtest = nameoftest test in my windows batch command. However, how can I run a xml script that contains many tests?
for anyone who stumbles upon this, you run an xml file via jenkins like this..
mvn test -DsuiteXmlFile = src/whatever/path/my_file.xml
I am completely new to using maven. I have created a maven project and exported it to eclipse. Maven automatically created the src/test/java and src/main/java.
I created a java script and successfully ran it in eclipse. But when I try running it through command line, I got an error that says:
cannot find or load main class.
When I checked my project directory, there were two classfile paths: classes and test-classes. The script I was running is the one in 'test-classes' but it is not the main class. But the path to the main class executes successfully but that is not where my script is located.
The command I was using for the main classfile is:
java -cp target/Test-1.0-SNAPSHOT.jar com.mycompany.App.
The command for the test classfile is :
java -cp target/Test-1.0-SNAPSHOT.jar com.mycompany.AppTest.
This second command gives me the error I mentioned.
Please how do I get around this issue?
By convention, everything in src/test/java is supposed to be for testing only. That is, you should place only your test classes in this directory. Maven will run them before building the final JAR, but it will NOT include them in it.
If you absolutely need a JAR with your test classes, have a look at How to create a jar containing test classes.
I have used the STS(Spring Tool Suite) to create a compiled groovy script which exists as a file on windows called Test.class. I am able to right click on the file in STS and execute it which works well.
However - I want to be able to execute the script on the windows command line, so far I have tried various ways but have not been successful. I have tried the following...
java -cp C:\Users\MyName\springsource\sts->
3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\
org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar Test.class
But that does not work it gives me an error --> Error: Could not find or load main class Test.class
Any Pointers?
You are trying to run a test case, so you really ned to be launching junit and ass this test as the test to run.
The easiest thing to do is to download a distribution of groovy, unzip, and run:
groovy Test.groovy
Step 1
In STS(Spring Tool Suite) ,Create a Groovy Class e.g. Customer.groovy file. Specify a Package Name e.g. com.customer. In the main method put in code to validate the code is being called e.g. println ‘test’.
Step 2
Go to your command line (Windows use command prompt). Switch\cd to the ROOT directory of your project. Execute the command below.
Step 3
execute java -cp C:\Users\Profile\springsource\sts-3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. com.customer.Customer
The code should run.
V Important
If like me, you do not have a class and you only have a groovy script then in step#3 specify the Groovy script name without the suffix.
Test is naked? (without package name?) try this.
java -cp C:\Users\MyName\springsource\sts-> 3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\ org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. package.Test
Pay attention to ;. and package name.