I like to customize and display more information for Test suites or tests like Test Run times, for eg: adding more information to below displayed output
===============================================
Demo-Suite
Total tests run: 19, Failures: 1, Skips: 0
===============================================
Any suggestions how to add more to above info like adding Average Test Suite run time etc.,
Here is the solution for you:
Let us assume we have a TestNG script with 3 Testcases, where 1 Testcase passes & 2 Testcases fails.
#Test
public void test1()
{
Assert.assertEquals(12, 13);
}
#Test
public void test2()
{
System.out.println("Testcase 2 Started");
Assert.assertEquals(12, 13, "Dropdown count doesnot match");
System.out.println("Testcase 2 Completed");
}
#Test
public void test3()
{
System.out.println("Testcase 3 Started");
Assert.assertEquals("Hello", "Hello", "Words doesnot match. Please raise a Bug.");
System.out.println("Testcase 3 Completed");
}
So you get the result on the console as: Tests run: 3, Failures: 2, Skips: 0
Now to look at the granular details you can do the following:
a. Move to the tab "Results of running class your_class_name". Here you will observe some more fine prints of the execution in-terms of Default Suite Execution Time, Default Test Execution Time, Time taken for each Individual Test, etc.
b. Now to view more details you can click on the "Open TestNG report" icon located on the top bar of "Results of running class your_class_name". This will provide you a lot more information about Testcase Results & Time taken.
Now if you need more detailed information in the form of Dashboard, Execution Info & System Details, you can integrate "ExtentReports" within TestNG to get some superb graphical representations of your test execution.
Dashboard:
Execution Info:
System Details:
Let me know if this answers your question.
Too long by 3 characters
to be a comment.
TestNG documentation is your friend. You could provide your own implementation. Very basic example here.
Another approach is to use HTML/XML Report generation and to inspect the data from a test run there. It's a bunch of html pages with pretty colors and some data. Sample report here. Also if your project is using Apache Maven than just enable the surefire plug-in. Sample report here.
Related
Is it possible in JUnit 5 to print a test summary at the end of all tests to the console?
It should contain a list of the tests that have failed, and a list of the ones that were successful.
try gradle test -i
this will print test cases with result and the final output result.
I'm confused in difference between Tests and Steps in testng extent report.
I have 2 test cases as 1 pass and 1 fail. In extent report under Test: 1 test(s) passed 1 test(s) failed, 0 others and under Steps: 1 step(s) passed
2 step(s) failed, 0 others
So would anyone clarify what is the difference between both ?
Attaching code snippet and testng extent report
#Test
public void demoTestPass()
{
test = extent.createTest("demoTestPass", "This test will demonstrate the PASS test case");
Assert.assertTrue(true);
}
#Test
public void demoTestFail()
{
test = extent.createTest("demoTestFail", "This test will demonstrate the FAIL test case");
Assert.assertEquals("Hi", "Hello");
}
Please click for Extent report here.
Any clarification would be much appreciated.
Difference Between Tests and Steps in extentReport:
Tests defines: Total test section which you have created in your Report: With the syntax like : extentReport.createTest("name of section");
Steps defines : Total number of log which you have generated in Script, With the syntax like : testlog.info() OR testlog.pass() OR testlog.fail() where testlog is object of ExtentTest class
Example:
In this report, there are 3 section which has been created and its showing as Tests. And Steps defines numbers of logs which has been passed in those Test.
Your case :
Test: 1 test(s) passed 1 test(s) failed, 0 others and under Steps: 1 step(s) passed 2 step(s) failed, 0 others
Test include 1 pass and 1 fail, because of its get failure in Steps. Your Steps include 1 pass and 2 fails and its reflected on Test.
Test(startTest("test name")) is something that is used to create a new test in extent reports.
Steps denotes that how many messages (test. Pass("pass message"), test. Fail ("fail message), test. Info ("info message")) you've logged to reports.
Consider you've two test methods and each test method has 1pass and 1 info messages.
So, in the extent reports, it'll show like 2 tests, total 4 steps.
2 pass steps and 2 info steps
I'm making a GUI for use of TestNG, currently I have a dropdown box which uses then allows you to press a button which I want to run a group of tests
#Test(groups = {"Group1"})
public void Test()
//Test Data
#Test(groups = {"Group1"})
public void Test2()
//Test Data
#Test(groups = {"Group2"})
public void Test3()
//Test Data
I'm currently running this code via the run configurations and calling the group to run there.
Is there any way I can do this via a button press so the user can press run Group1 and then run Group2 in an executable program?
You can create a synthetic testng.xml in the Java code using the group inputs. But this might get messy with large size testng.xml.
You can also call testng from the command line (Have to figure out this from your GUI code) which has many parameters available like include groups, exclude groups etc etc.
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...] -groups "grp1,grp2"
Refer to [http://testng.org/doc/documentation-main.html#running-testng}
You can make use of BeanShell feature that TestNG provides for doing this. You can define a JVM argument that reads the value set using the drop down selected option and then run it.
You can read more about using Beanshell and TestNG from this blog post that I created.
I have some parameterized test with Spock, and it's 10 cases which coming to test in where block. So, I decide to use #Unroll annotation so when some of the 10 cases fail, I will understand which one.
So I add to feature placeholder with message about what kind of case it is, let's say it's
"Test with #message case"(String message, etc..){...}.
If I'll try to launch it in IDEA, output is looks like expected. (in the left side of the window where tree of tests is opened)
Test with SomeIterationMessage case: failed
Test with AnotherIterationMessage case: failed
But console IDEA output is looks like:
Condition not satisfied:
resultList.size() == expectedSize
| | | |
[] 0 | 1
false
<Click to see difference>
at transformer.NameOfSpec.Contract. Test with #message case (NameOfSpec.groovy:220)
If I launch building the project by Maven through command line and this tests failed I just get messages like in IDEA Console output. So it's absolutely useless and like in the IDEA Console output.
Test with #message case: failed
Test with #message case: failed
So it does not replace placeholders with particular iteration data to get info about which iteration was crushed.
How to figure it out so the IDEA console output and the Maven outputs get it right? 'Cause if it impossible, this #Unroll annotation really piece of nothing. 'Cause in IDE test can pass with no problem, but in a big project with tons of dependencies it can crush when you build it, and you will never get why and which iteration failed cause output is telling you nothing.
Okay, so it's can be used with Maven with no problem. In the IDE we can use our panel with a tree of tests. It works fine as I said before.
And what about maven. Yes, it doesn't show anything in console output. But when the test was failed we can go to the
target\surefire-reports
In the root of our module which Maven generate for each of the class and fill with outputs, and get right name of iteration with actual iteration data.
-------------------------------------------------------------------------------
Test set: *************************.***MapReduceSpec
-------------------------------------------------------------------------------
Tests run: 6, Failures: 0, Errors: 3, Skipped: 1, Time elapsed: 0.938 sec <<< FAILURE! - in *******************.DmiMapReduceSpec
MapReduce flow goes correctly for dataclass (contract) (*******************.***MapReduceSpec) Time elapsed: 0.185 sec <<< ERROR!
Where value "(contract)" in the end of method string, has been taken from iteration parameter #message. So raw method name looks like
"MapReduce flow goes correctly for dataclass (#message)"(){...}
Of course, it's not a very cool trick, but it's anyway much faster, then debug 20 or even more inputs in where block manually figuring out which is dead.
I have a java file which has 7 junit tests to run. If I run all the tests at once all but 1 passes. If I comment out certain tests and that one test always passes.
Can anybody offer any suggestions as to what could be causing this?
My first thought was something in the test Setup or cleanup but I am not sure what it could be. All I do in the clean up is exit the driver and output the time taken to run the test.
In the setup I set up the driver, the time started, create a firefox profile and read in some data from a properties file to use in the tests.
If it was the setup / cleanup surely the other 6 tests would also be effected? The test that fails is a simple test to check that entering an invalid card type displays an error message on the page.
UPDATE:
I've renamed the test so it runs first and now all 7 pass each time. What could be causing this? Do I need to set something in my test cleanup to get it back to a default state?
My test cleanup:
#After
public void testCleanup() throws IOException {
driver.quit();
endTime = System.currentTimeMillis();
long totalTime = ((endTime - startTime)/1000)/60;
System.out.println();
System.out.println("Test Suite Took: " + totalTime + " Minutes.");
}