use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class TestNGFormatter method handleTestRunFinished.
private void handleTestRunFinished(TestRunFinished event) {
try {
Instant finished = event.getInstant();
Duration duration = Duration.between(started, finished);
results.setAttribute("total", String.valueOf(getElementsCountByAttribute(suite, "status", ".*")));
results.setAttribute("passed", String.valueOf(getElementsCountByAttribute(suite, "status", "PASS")));
results.setAttribute("failed", String.valueOf(getElementsCountByAttribute(suite, "status", "FAIL")));
results.setAttribute("skipped", String.valueOf(getElementsCountByAttribute(suite, "status", "SKIP")));
suite.setAttribute("name", TestNGFormatter.class.getName());
suite.setAttribute("duration-ms", String.valueOf(duration.toMillis()));
test.setAttribute("name", TestNGFormatter.class.getName());
test.setAttribute("duration-ms", String.valueOf(duration.toMillis()));
TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult streamResult = new StreamResult(writer);
DOMSource domSource = new DOMSource(document);
transformer.transform(domSource, streamResult);
closeQuietly(writer);
} catch (TransformerException e) {
throw new CucumberException("Error transforming report.", e);
}
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class EncodingParser method read.
private static String read(Resource resource, String encoding) {
char[] buffer = new char[2 * 1024];
final StringBuilder out = new StringBuilder();
try (InputStream is = resource.getInputStream();
InputStreamReader in = new InputStreamReader(is, encoding);
BufferedReader reader = new BufferedReader(in)) {
int read;
while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
out.append(buffer, 0, read);
}
} catch (IOException e) {
throw new CucumberException("Failed to read resource:" + resource.getUri(), e);
}
return out.toString();
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_with_null_arguments.
@Test
void throws_could_not_invoke_step_when_execution_failed_with_null_arguments() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have an null value\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have an {word} value", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class);
List<Argument> arguments = asList(() -> null);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not invoke step [I have an {word} value] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (null)")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_and_no_arguments.
@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_and_no_arguments() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have cukes in my belly", Integer.TYPE, Short.TYPE, List.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have cukes in my belly] is defined with 3 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 0 arguments.\n" + "Step text: I have cukes in my belly")));
}
use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_register_type_in_configuration_exception_when_there_is_no_data_table_type_defined.
@Test
void throws_register_type_in_configuration_exception_when_there_is_no_data_table_type_defined() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have a data table\n" + " | A | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have a data table", UndefinedDataTableType.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have a data table] defined at '{stubbed location with details}'.\n" + "It appears you did not register a data table type.")));
}
Aggregations