This question already has answers here:
How to order feature files in Cucumber test suite?
(6 answers)
Closed 3 years ago.
I have 3 separate feature files and one CucumberRunnerClass. As per the sequence need to execute those are listed below:
Feature files : Login.feature, NavigateCusMngt.feature, AddCustomer.feature
However, when executing it goes to first execute the AddCustomer.feature, then Login.feature and finally
NavigateCusMngt.feature.
Therefore, I observed AddCustomer.feature - skipped, system logged in then NavigateCusMngt.feature -gives errors.
#CucumberOptions(
features = {"src/test/resources/features/Login.feature", "src/test/resources/features/NavigateCusMngt.feature", "src/test/resources/features/AddCustomer.feature"},
glue = {"phptravelstestcases"},
tags = {"~#Ignore"},
format = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty/mercury-tours-RegisterUserTest",
"json:target/cucumber-reports/json-reports/mercury-tours-RegisterUserTest.json",
"rerun:target/cucumber-reports/rerun-reports/mercury-tours-RegisterUserTest.txt"
}
)
please give me a solution.
The feature files are parsed alphabetically. I named mine with a starting letter in the right order, e.g.
A-Login.feature
B-NavigateCusMngt.feature
C-AddCustomer.feature
It's not ideal in the long run, but it is a workable solution.
Related
1000 feature files in src/test/resources.
I want to run only the features file which are even( 2, 4, 6,......1000)
how can we do that?
I tried to group them but not sure like this will be good approach.
If you are using JUnit 5 with Cucumber the you can use a PostDiscoveryFilter from the JUnit Platform to filter out tests.
Something like:
public FilterResult apply(TestDescriptor t) {
// Determine if test descriptor is a feature file based on t.getSource()
Collection siblings = t.getParent().getChildren();
// Find index of t in siblings
// decide to keep or not if index is even
}
I found another similarly titled question here, 42878832, but it didn't answer my question.
I am running Cucumber and would like to customise my TestRunner by specifying CucumberOptions. I am trying to add values to the plugin option and am following an example where it's specified a value of progress as one of the allowed values. When I run my code I don't see it producing the expected output .P- so am thinking that perhaps the version I am using today doesn't support this feature anymore. I am using Intellij (2020.2), Java (15), cucumber-java (6.8.1).
Does anyone know where the options are documented and more specifically where can I read the list of available options for the plugin option. I found this page CucumberOptions docs on the Cucumber site but it wasn't very helpful.
My TestRunner class looks like below.
#RunWith(Cucumber.class) #CucumberOptions(
features = {"cucumber/features"},
glue = {"steps"},
plugin = {"progress", "pretty", "html:Report1"},
dryRun = false,
monochrome = true
//tags = {"#P1"}
//name = {"Logo"}
) public class TestRunner { }
You can find the listed options in here
In javadoc:
look here
If you want to have an idea , how some of them works, have a look here
Here is a question that says about how to use progress
This question already has answers here:
Conditionally ignoring tests in JUnit 4
(5 answers)
Closed 5 years ago.
I have a junit integration test that runs on our build machine, and calls an external server. We use a gating build - so code doesn't make it in to the main branch unless we get 100% of tests passing
Occasionally, the external server goes down for a while, and the test fails, but with a definitive exception that I can catch. I really don't want the test to fail the build, therefore blocking code getting in - but I also would prefer it's not marked as "passed". So I want to sort of mark it as a warning, ignored, or indeterminate result. This would be ideal:
#Test
public void someTest()
{
try
{
do whatever
}
catch (ServerDownException theException)
{
junit.markThisTestAsIgnored(); <---- something like this
}
}
found it -
throw new AssumptionViolationException( "skipping test because xxx is down");
One option is to set a category(stress category for example).
Check out this link:
https://github.com/junit-team/junit4/wiki/categories
If you want, you can put the #Ignore rule:
https://dzone.com/articles/allowing-junit-tests-pass-test
Regards
This question already has answers here:
Run piece of code contained in a String
(9 answers)
Closed 6 years ago.
Lets say i have this String: String run = "System.out.println\(\"Hello\"\)". What i want to do is run what is in the string to output Hello in console.
Maybe there is a method like String.run()?
Try BeanShell , build your app with jar library.
import bsh.Interpreter;
private void runString(String code){
Interpreter interpreter = new Interpreter();
try {
interpreter.set("context", this);//set any variable, you can refer to it directly from string
interpreter.eval(code);//execute code
}
catch (Exception e){//handle exception
e.printStackTrace();
}
}
Maybe in Java 9 you could use the REPL but as it's not there yet You would need to
* create a temporary file with a class with a know to You API
* run javac on it and compile it
* load the compiled class with a class loader
* run the code
If You want to do is running dynamically defined scripts in Your code then You could use Nashorn and JavaScript. It would do what You want. Also You could use Groovy in your project instead of Java - the syntax is similar to Java but Groovy is a dynamic language.
No, you cannot do it and there's no method to run this command in String. Anything withing the double quotes becomes String literals only and compiler doesn't take care of any command written in that.
This question already has answers here:
Run single test from a JUnit class using command-line
(4 answers)
Closed 9 years ago.
I am trying to run tests from a separate class where information can be compiled and reported. I am having difficulty running individual tests, however.
I tried:
for (int i = 0; i < testRuns; i++) {
JUnitCore.runClasses(InternetExplorerTestClass.class, MozillaFirefoxTestClass.class, GoogleChromeTestClass.class);
}
but that limits the control I have over the results and reporting the data.
How do I run a single test from a test suite? Thank you in advance.
It almost looks like you are doing something like a Selenium test? If you use Gradle as your build tool, you can easily run one specific test by using the "include" filter option like so. (You could do something similar with Ant, SBT, or Maven as well). Personally, I think using the build tool to pick the tests to run is more elegant than writing code to run certain classes.
tasks.withType(Test) {
jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
maxParallelForks = 4
// System properties passed to tests (if not http://localhost:8001/index.html)
systemProperties['testProtocol'] = 'http'
systemProperties['testDomain'] = 'djangofan.github.io'
systemProperties['testPort'] = 80
systemProperties['testUri'] = '/html-test-site/site'
systemProperties['hubUrl'] = 'localhost'
systemProperties['hubPort'] = '4444'
}
task runParallelTestsInFirefox(type: Test) {
description = 'Runs all JUnit test classes in parallel threads.'
include '**/TestHandleCache*.class'
testReportDir = file("${reporting.baseDir}/ParallelTestsFF")
testResultsDir = file("${buildDir}/test-results/ParallelTestsFF")
// System properties passed to tests
systemProperties['browserType'] = 'firefox'
// initial browser size and position
systemProperties['windowXPosition'] = '100'
systemProperties['windowYPosition'] = '40'
systemProperties['windowWidth'] = '400'
systemProperties['windowHeight'] = '600'
}
This is taken from a example project I wrote here.