Search in sources :

Example 81 with Description

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;
}
Also used : TestCompiler(fr.inria.diversify.utils.compilation.TestCompiler) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) Logger(org.slf4j.Logger) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) DSpotCompiler(fr.inria.diversify.utils.compilation.DSpotCompiler) DSpotUtils(fr.inria.diversify.utils.DSpotUtils) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Description(org.junit.runner.Description) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Failure(org.junit.runner.notification.Failure) AssertGenerator(fr.inria.diversify.dspot.assertGenerator.AssertGenerator) ArrayList(java.util.ArrayList) TestSelector(fr.inria.diversify.dspot.selector.TestSelector) List(java.util.List) CtType(spoon.reflect.declaration.CtType) Amplifier(fr.inria.diversify.dspot.amplifier.Amplifier) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) ModifierKind(spoon.reflect.declaration.ModifierKind) TestListener(fr.inria.stamp.test.listener.TestListener) Collections(java.util.Collections) CtMethod(spoon.reflect.declaration.CtMethod) Set(java.util.Set) Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) TestListener(fr.inria.stamp.test.listener.TestListener) CtMethod(spoon.reflect.declaration.CtMethod)

Example 82 with Description

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");
        }
    };
}
Also used : Description(org.junit.runner.Description) Statement(org.junit.runners.model.Statement) IOException(java.io.IOException) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) URL(java.net.URL) TakesScreenshot(org.openqa.selenium.TakesScreenshot)

Example 83 with Description

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());
}
Also used : PickleRunner(io.cucumber.junit.PickleRunners.PickleRunner) Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) TestPickleBuilder.picklesFromFeature(io.cucumber.junit.TestPickleBuilder.picklesFromFeature) Test(org.junit.jupiter.api.Test)

Example 84 with Description

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);
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) Description(org.junit.runner.Description) WithStepDescriptions(io.cucumber.junit.PickleRunners.WithStepDescriptions) Step(io.cucumber.plugin.event.Step) Test(org.junit.jupiter.api.Test)

Example 85 with Description

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());
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)57 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)25 RunListener (org.junit.runner.notification.RunListener)23 IOException (java.io.IOException)22 Request (org.junit.runner.Request)21 Method (java.lang.reflect.Method)18 JUnitCore (org.junit.runner.JUnitCore)17 Test (org.junit.jupiter.api.Test)14 Filter (org.junit.runner.manipulation.Filter)14 File (java.io.File)13 Runner (org.junit.runner.Runner)13 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 RunNotifier (org.junit.runner.notification.RunNotifier)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 Description.createTestDescription (org.junit.runner.Description.createTestDescription)9