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.
Related
In my Karate runner I am using .outputCucumberJson(true) as shown below to generate a Cucumber Report (in order to upload this back to our XRAY tests):
class KarateRunnerTest {
#Test
void testParallel() {
Results results = Runner.path("classpath:apiTesting/karateFeatureFiles/")
.outputCucumberJson(true)
.parallel(5);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
}
However, it is producing one report for each Feature File.
Is there a way for it to just generate one report for all Feature Files?
So this currently can't be done in Karate.
As a workaround I used a little npm tool called 'cucumber-json-merge'.
This merged the reports into 1 and seems to work fine.
I know using this reflection we can surely get list of all groups of the #test.
#BeforeMethod
public void befrMethod(Method met){
Test t = met.getAnnotation(Test.class);
System.out.println(t.groups());
}
But Is there a way to get groups list while inside the #test and not beforemethod?
Because I am running tests in parallel and this method is not working well for me.
Test method supports ITestContext dependency injection
And this class has a method called
getIncludedGroups java.lang.String[] getIncludedGroups() Returns: All
the groups that are included for this test run.
"ITestContext (testng 7.3.0 API)" https://javadoc.io/doc/org.testng/testng/latest/org/testng/ITestContext.html
So try
#Test
public void befrMethod(ITestContext met){
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
}
}
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:
#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.