I am having one suit say Suite1
in Suite1 I am calling two class methods Test1 and Test2 respectively with test annotation #Test and having main method with #Beforesuite and #AfterSuite annotation - when I run the suite using Test NG - it runs only the second method and first method always fails and below it the trace of failed result.
I am just curious why always last test pass and this happens when I use selenium keyword but I use standard java keyword like system.out.println(); it pass the test
Related
We have few test methods which have switch cases in it based on different functionality. When one of the functionality fails; we get invocation-number parameter in failed testng ex. invocation-number = "0 3 7" based on the failed case. Can we use this to run the single test method in parallel based on the switch cases in it?
I have one requirement as follows
- When my #Test method executes, check the log files.
- If there any exception in log files, fail the test case. Else pass the test case
Currently, I have done following implementation
- Clearing the log files (3-4 log files) in #Beforetest code
- Checking exceptions in all log files in #AfterTestCode
But issue is that, when any #Test method pass/fail, control marks that test case execution status as PASS/FAIL and after this althoug there is any exception in my log file, my TC passes.
So can you please suggest me if any workarounds possible for that.
Vishal
Checking exception in the #AfterMethod will not help because it checks the result of the #Test method.
For example :
#Test
Public void testCase(){
}
#AfterMethod
public void tearDown(ITestResult result){
}
In the above sample result is for the #test method class result. If test case is passing it will understand pass in #AfterMethod as well.
Workaround:
Either check in your #Test method and based on that your AfterMethod will work fine considering the fact that #AfterMethod will execute after every test method class.
Create a #AfterClass Method which will check on all test cases whether they are passed or not at the end of the class.
I run parametrized test with Junit, but I want to skip some tests following a flag. The parameters are stored in a CSV file and when a flag is "off" I want to skip this test. How can I do this?
You can use the Assume class.
#Test
public void something() throws Exception {
Assume.assumeFalse(valueFromCsv.equals("off"));
}
The test will be skipped by JUnit if the assumption is not fulfilled.
I have suppose 10 test cases in test suite in which 2 test cases are disabled.I want to get those two test cases in test result of jenkins job like pass = 7 ,fail = 1 and disabled/notrun= 2.
By default, TestNG generates report for your test suite and you may refer to index.html file under the test-output folder. If you click on "Ignored Methods" hyperlink, it will show you all the ignored test cases and its class name and count of ignored methods.
All test cases annotated with #Test(enabled = false) will be showing in "Ignored Methods" link.
I have attached a sample image. Refer below.
If your test generates JUnit XML reports, you can use the JUnit plugin to parse these reports after the build (as a post-build action). Then, you can go into your build and click 'Test Result'. You should see a breakdown of how the execution went (including passed, failed, and skipped tests).
I have:
#OnApplicationStart
public class SomeClass {
.. doJob() ...
}
How I can test it in my Unit Test that doJob() actually launched when application started?
I would argue that this is not a unit test, but an integration test.
You can test your Job, by simply calling it using the syntax new MyJob().now();, but as you are looking to test the #OnApplicationStart function, the you would be better off doing this as a Selenium test, and checking the data that you expect to be made available from the bootstrap job is present.