Ignore a junit test with parametrized test - testing

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.

Related

karate.callSingle getting call twice for two tests

I am trying to integrate karate in my project for integration testing. I was trying to use karate.callSingle() to fetch authorization headers.
I have two tests
#Test
void test1() {
Results results = Runner.path("classpath:integrationTests/test1.feature").parallel(2);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
#Test
void test2 {
Results results = Runner.path("classpath:integrationTests/test2.feature").parallel(1);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
Now the test1.feature has two scenarios and test2.feature has one scenario. The tests are running fine just that in the logs I see karate.callSingle is executed twice...for both tests. Is this the expected behaviour?
Yes thats the expected behavior. karate.callSingle() is scoped to a single instance of a Runner.

Execute single selenium test multiple times in parallel

I was wondering if anyone had any advice of an easy way or executing a single selenium test multiple times in parallel.
I have 1 test that I would like to execute, it will then spin up 10 chrome instances and run the test 10 times in parallel, its an idea to test load/performance.
I could split the test up into individual classes and get them to run in parallel but this is a bit overkill, is there a simpler way of running this with Nunit?
Tests are written in c# and we are using NUnit at the test runner, we are using BDDfy for the test language.
Bit of a difficult question to write down but hope some people understand what I am trying to achieve
You can do it by adding multiple test cases on the same test, even if you don't have any parameters to pass to the test, and use ParallelScope.All on fixture to run all testcases within the fixture in parallel.
[TestFixture, Parallelizable(ParallelScope.All)]
public class MyTestFixture
{
private static readonly IEnumerable<string> TestCases = new List<string>(new string[10]);
[TestCaseSource(nameof(TestCases))]
public void SingleTestRepeatedMultipleTimes(string testCase)
{
//test steps
}
}

Webdriver - Check for exceptions in log files

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.

Selenium multiple test run fails

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

How to test Jobs in playframework?

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.