use of org.junit.runner.Description in project dspot by STAMP-project.
the class Amplification method amplification.
/**
* Amplification of a single test.
*
* <p>DSpot combines the different kinds of I-Amplification iteratively: at each iteration all kinds of
* I-Amplification are applied, resulting in new tests. From one iteration to another, DSpot reuses the
* previously amplified tests, and further applies I-Amplification.
*
* @param classTest Test class
* @param test Method to amplify
* @param maxIteration Number of amplification iterations
* @return Valid amplified tests
* @throws IOException
* @throws InterruptedException
* @throws ClassNotFoundException
*/
private List<CtMethod<?>> amplification(CtType<?> classTest, CtMethod test, int maxIteration) throws IOException, InterruptedException, ClassNotFoundException {
List<CtMethod<?>> currentTestList = new ArrayList<>();
currentTestList.add(test);
List<CtMethod<?>> amplifiedTests = new ArrayList<>();
for (int i = 0; i < maxIteration; i++) {
LOGGER.info("iteration {}:", i);
List<CtMethod<?>> testsToBeAmplified = testSelector.selectToAmplify(currentTestList);
if (testsToBeAmplified.isEmpty()) {
LOGGER.info("No test could be generated from selected test");
continue;
}
LOGGER.info("{} tests selected to be amplified over {} available tests", testsToBeAmplified.size(), currentTestList.size());
currentTestList = AmplificationHelper.reduce(inputAmplifyTests(testsToBeAmplified));
List<CtMethod<?>> testsWithAssertions = assertGenerator.generateAsserts(classTest, currentTestList);
if (testsWithAssertions.isEmpty()) {
continue;
} else {
currentTestList = testsWithAssertions;
}
TestListener result = compileAndRunTests(classTest, currentTestList);
if (result == null) {
continue;
} else if (!result.getFailingTests().isEmpty()) {
LOGGER.warn("Discarding failing test cases");
final Set<String> failingTestCase = result.getFailingTests().stream().map(Failure::getDescription).map(Description::getMethodName).collect(Collectors.toSet());
currentTestList = currentTestList.stream().filter(ctMethod -> !failingTestCase.contains(ctMethod.getSimpleName())).collect(Collectors.toList());
}
currentTestList = AmplificationHelper.getPassingTests(currentTestList, result);
LOGGER.info("{} test method(s) has been successfully generated", currentTestList.size());
amplifiedTests.addAll(testSelector.selectToKeep(currentTestList));
}
return amplifiedTests;
}
use of org.junit.runner.Description in project camunda-bpm-platform by camunda.
the class SeleniumScreenshotRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} catch (Throwable t) {
captureScreenShot(description);
throw t;
}
}
public void captureScreenShot(Description describe) {
File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
String now = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
String scrFilename = describe.getClassName() + "-" + describe.getMethodName() + "-" + now + ".png";
File outputFile = new File(computeScreenshotsRoot(describe.getTestClass()), scrFilename);
log.info(scrFilename + " screenshot created.");
try {
FileUtils.copyFile(scrFile, outputFile);
} catch (IOException ioe) {
log.severe("Error copying screenshot after exception.");
}
}
public File computeScreenshotsRoot(Class anyTestClass) {
final String clsUri = anyTestClass.getName().replace('.', '/') + ".class";
final URL url = anyTestClass.getClassLoader().getResource(clsUri);
final String clsPath = url.getPath();
final File root = new File(clsPath.substring(0, clsPath.length() - clsUri.length()));
final File clsFile = new File(root, clsUri);
return new File(root.getParentFile(), "screenshots");
}
};
}
use of org.junit.runner.Description in project cucumber-jvm by cucumber.
the class PickleRunnerWithStepDescriptionsTest method shouldIncludeScenarioNameAsClassNameInStepDescriptions.
@Test
void shouldIncludeScenarioNameAsClassNameInStepDescriptions() {
Feature features = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: In cucumber.junit\n" + " Scenario: first\n" + " When step\n" + " Then another step\n" + "\n" + " Scenario: second\n" + " When step\n" + " Then another step\n");
PickleRunner runner = PickleRunners.withStepDescriptions(context, features.getPickles().get(0), null, createJunitOptions());
// fish out the data from runner
Description runnerDescription = runner.getDescription();
Description stepDescription = runnerDescription.getChildren().get(0);
assertEquals("first", stepDescription.getClassName());
assertEquals("step", stepDescription.getMethodName());
assertEquals("step(first)", stepDescription.getDisplayName());
}
use of org.junit.runner.Description in project cucumber-jvm by cucumber.
the class PickleRunnerWithStepDescriptionsTest method shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario.
@Test
void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() {
List<Pickle> pickles = picklesFromFeature("path/test.feature", "" + "Feature: FB\n" + "# Scenario with same step occurring twice\n" + "\n" + " Scenario: SB\n" + " When foo\n" + " Then bar\n" + "\n" + " When foo\n" + " Then baz\n");
WithStepDescriptions runner = (WithStepDescriptions) PickleRunners.withStepDescriptions(context, pickles.get(0), null, createJunitOptions());
// fish out the two occurrences of the same step and check whether we
// really got them
Step stepOccurrence1 = runner.getChildren().get(0);
Step stepOccurrence2 = runner.getChildren().get(2);
assertEquals(stepOccurrence1.getText(), stepOccurrence2.getText());
// then check that the descriptions are unequal
Description runnerDescription = runner.getDescription();
Description stepDescription1 = runnerDescription.getChildren().get(0);
Description stepDescription2 = runnerDescription.getChildren().get(2);
assertNotEquals(stepDescription1, stepDescription2);
}
use of org.junit.runner.Description in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method should_not_create_step_descriptions_by_default.
@Test
void should_not_create_step_descriptions_by_default() {
Feature cucumberFeature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + " Background:\n" + " Given background step\n" + " Scenario: A\n" + " Then scenario name\n" + " Scenario: B\n" + " Then scenario name\n" + " Scenario Outline: C\n" + " Then scenario <name>\n" + " Examples:\n" + " | name |\n" + " | C |\n" + " | D |\n" + " | E |\n");
FeatureRunner runner = createFeatureRunner(cucumberFeature, new JUnitOptions());
Description feature = runner.getDescription();
Description scenarioA = feature.getChildren().get(0);
assertTrue(scenarioA.getChildren().isEmpty());
Description scenarioB = feature.getChildren().get(1);
assertTrue(scenarioB.getChildren().isEmpty());
Description scenarioC0 = feature.getChildren().get(2);
assertTrue(scenarioC0.getChildren().isEmpty());
Description scenarioC1 = feature.getChildren().get(3);
assertTrue(scenarioC1.getChildren().isEmpty());
Description scenarioC2 = feature.getChildren().get(4);
assertTrue(scenarioC2.getChildren().isEmpty());
}
Aggregations