I have a issue with the TestNG plugin in IntelliJ. I run my tests by using a testng.xml. The I define parameters on the suite and test level.
If I want to run only one test from IntelliJ by selecting it and run as debug, IntelliJ copies the test into a temporary testng.xml like this one:
/Users/robert/Library/Caches/IntelliJIdea2016.1/temp-testng-customsuite.xml
The problem is, the suite has no parameters defined in my testng.xml file. So TestNG ignores the test because it misses the parameters that doesn't match to the test #Parameters declaration.
How to run a single TestNG test in IntelliJ with using of parametrized testng.xml?
Best regards
Robert
Try this:
On IntelliJ, go to Run > Edit Configurations > Select tab Configuration > Select tab Parameters.
There, add the desired parameters.
Related
How does TestNG work when it is looking for its test classes?
I created a separate project from my TestNG project using JavaFX to create a GUI, when the GUI is run it enables you to select an XML file and then the path to the testNG XML is saved in a variable.
When I run the following code:
String xmlFileName = selectedFile.getAbsolutePath();
TestNG testng = new TestNG();
List<String> testFilesList = new ArrayList<String>();
testFilesList.add(xmlFileName); //test suite resides in the working directory's root folder
testng.setTestSuites(testFilesList); //you can addd multiple suites either here by adding multiple files or include all suites needed in the testng.xml file
testng.setUseDefaultListeners(false);
testng.addListener(htmlRep);
testng.run();
I get an error saying that it cannot find my test classes inside the XML.
[TestNG] [ERROR]
Cannot find class in classpath: com.emc.qe.u360.tests.LogoutTests
I then decided to make a java class within my TestNG project, and copy the code over and it still gives the same error message.
Where is TestNG looking for the test classes when the above code is run?
What difference is the code above from manually running the XML from eclipse itself? The code seems to be working, as from what I can see if the code for running the XML was broken or not working, it wouldn't be able to give me that error as it wouldn't be able to determine what is specified in the XML.
Any help would be appreciated, thank you.
EDIT: Just for background information, currently I am using Jenkins to run the tests, what I'm trying to do with the GUI is to create an alternative solution to running the tests outside of the Project/Framework, that can be used universally, a user can just select their XML and then the tests will be executed.
It's configurable if you use the Maven Surefire or the Gradle TestNG runner, but by default I think TestNG looks in src/test/java for your class names. Additionally, I think if your running TestNG from code, as a standalone run, you might be able to adjust the path-base where it looks for classes.
I have defined my tests in a parametrized testng.xml. I use the Failsafe plugin and run my tests with mvn verify. The whole suite is executed.
What if I have to run only one single test from my testng.xml suite? I want that the parameters will be used, but I want to run only one test from the command line.
The maven parameter:
-Dit.test=CheckoutIT#testOrderId
does not work because maven runs the test directly without testng.xml, the parameters are not bind and the test will be ignored.
Is there a way to do it? A workaround is to create a temporary suite xml with only one test but it can't be a solution...
Best regards Robert
According to testng doc:
The command line flags that specify what tests should be run will be ignored if you also specify a testng.xml file, with the exception of -includedgroups and -excludedgroups, which will override all the group inclusions/exclusions found in testng.xml.
Another solution is to add listener to your maven goal which will parse your testng.xml and get test parameters to apply them to your current test.
How can I find tests that have not been added to a test suite?
If I run the test suite I get say 1000 tests but if I run a file search for "#Test" I get 1020 results. How can I go and add the missing ones without having to go through every search result and comparing to the tests that ran to see which ones are missing?
Use Eclipse itself to create a test suite. From the context menu of the project, select 'New -> Other' and select JUnit test suite. It will list out all the test classes in the project. By default, it creates a AllTests.java source file.
I am currently working on a Maven Project, using JUnit for defining tests and Jenkins for CI and am looking into how I can group my tests.
Say I had a test class with 20 tests, but I don't want to run all 20 tests, I want to be able to configure which tests to run. For Example, in another standalone project using TestNG and Selenium you can create a test method with the following annotation:
#Test (groups = { "AllTest" })
public void myTestMethod()
{
.. do something
.. assert something
}
... and then I am able to call which group to run based on an XML configuration.
Is it possible to define such type of groupings using Jenkins? I have researched into this and came across the plugin "Tests Selector Plugin" however can't understand how to get started once I've installed the plugin. There is a Wiki Page for it but I can't understand what to do after installing.
I have copy pasted the example property file, and didn't really understand what I needed to manipulate in it. When building, I simply get that the property file cannot be found or Jenkins doesn't have permission; can't find a way around this either :(
It's possible via maven + maven-surefire-plugin
http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
You can run a single test, set of tests or tests by regexp.
I have a java project in eclipse, when I press the project right click -> run as junit some tests do not run. I attached a picture, see YamiMailSenderTest for example.
When I try to run the tests directly they are running.
I am using eclipse 3.7.2.
and expanded view:
Any idea?
Ran into the same problem, my error was that I wrote: public void myMethodName(){ //assertions }
instead of: public void testMyMethodName() { //assertions }
the test before the MyMethodName is important.
It's a bit late, but in case anyone finds this via a search engine:
If a Test is run multiple times the results provided by JUnit are indistinguishable for those Tests and thus the results are only displayed for one run. See also the following Eclipse bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=172256
Check if you are excluding tests from run by attributes and check under Run > Run Configurations if your JUnit configuration are excluding any tests.
In jUnit 4, a test case needs to have #Test annotation. The test case can be set to ignore with #Ignore annotation. The whole test class can also be set to ignore by placing the #Ignore annotation right above the class declaration. Note: In jUnit 4 , there is no need to extend Testcase class as in jUnit 3. Everything is in annotation.
I have no idea about jUnit 3 since I use only 4.
I had a similar problem. For some reason, the "Run As -> jUnit Test" was always skiping the first test package. I was on an older version of Eclipse and SpringSource.
I moved back to Juno - Version: 4.2.1 and all my test run when I perform: "Run As -> jUnit Test. "
I had the same problem. Eclipse would only recognize and run 5 out of my 9 tests. After much troubleshooting I found this trick to convince Eclipse to recognize the remaining tests: just open each file, hit space and then backspace to mark it as changed, and save it. Then, Eclipse will recognize it as a test.