Search in sources :

Example 6 with TestListener

use of fr.inria.stamp.test.listener.TestListener in project dspot by STAMP-project.

the class TestLauncherTest method testRunningAllKindOfTests.

@Test
public void testRunningAllKindOfTests() throws Exception {
    Launcher launcher = new Launcher();
    launcher.getEnvironment().setSourceClasspath(System.getProperty("java.class.path").split(System.getProperty("path.separator")));
    launcher.addInputResource("src/test/resources/src/");
    launcher.addInputResource("src/test/resources/test/");
    launcher.buildModel();
    final String classpath = "src/test/resources/MockitoDemo-1.0-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/MockitoDemo-1.0-SNAPSHOT-tests.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT-tests.jar";
    /*
			Test that we the same entry point we are able to run all kind of test
		 */
    InputConfiguration configuration = new InputConfiguration("src/test/resources/mockito/mockito.properties");
    configuration.setInputProgram(new InputProgram());
    // Mocked
    TestListener results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"));
    assertEquals(5, results.getRunningTests().size());
    assertEquals(1, results.getFailingTests().size());
    assertEquals(4, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
    results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"), Collections.singleton("testGetBook"));
    assertEquals(1, results.getRunningTests().size());
    assertEquals(0, results.getFailingTests().size());
    assertEquals(1, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
    configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
    configuration.setInputProgram(new InputProgram());
    // Default
    results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.TestSuiteExample"), Collections.singleton("test1"));
    assertEquals(1, results.getRunningTests().size());
    assertEquals(1, results.getFailingTests().size());
    assertEquals(0, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
    configuration = new InputConfiguration("src/test/resources/sample/sample.properties");
    configuration.setInputProgram(new InputProgram());
    // Abstract Class: using implementation of abstract class to run test
    results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.InheriteTest"));
    assertEquals(2, results.getRunningTests().size());
    assertEquals(0, results.getFailingTests().size());
    assertEquals(2, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
    // will use example.InheriteTest to run the test of AbstractTest
    results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"), Collections.singleton("abstractTest"));
    assertEquals(1, results.getRunningTests().size());
    assertEquals(0, results.getFailingTests().size());
    assertEquals(1, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
    results = TestLauncher.run(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"));
    assertEquals(2, results.getRunningTests().size());
    assertEquals(0, results.getFailingTests().size());
    assertEquals(2, results.getPassingTests().size());
    assertEquals(0, results.getAssumptionFailingTests().size());
    assertEquals(0, results.getIgnoredTests().size());
}
Also used : Launcher(spoon.Launcher) TestListener(fr.inria.stamp.test.listener.TestListener) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test)

Example 7 with TestListener

use of fr.inria.stamp.test.listener.TestListener in project dspot by STAMP-project.

the class TestLauncherTest method testTimeoutTuning.

@Test
public void testTimeoutTuning() throws Exception {
    /*
			Contract: DSpot is able to tune the timeout of the test runner.
				We test that with a small time (0), DSpot throws a TimeoutException exception.
				We test that with a enough large time (10000, default value) DSpot runs the test correctly.
		 */
    Utils.init("src/test/resources/sample/sample.properties");
    AmplificationHelper.setTimeOutInMs(0);
    final CtClass aClass = Utils.findClass("fr.inria.systemproperties.SystemPropertiesTest");
    final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputConfiguration());
    try {
        TestLauncher.run(Utils.getInputConfiguration(), classPath, aClass);
        fail("testTimeoutTuning should have thrown a java.util.concurrent.TimeoutException");
    } catch (Exception e) {
        assertTrue(e instanceof java.lang.RuntimeException);
        assertTrue(e.getCause() instanceof java.util.concurrent.TimeoutException);
    }
    AmplificationHelper.setTimeOutInMs(10000);
    final TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classPath, aClass);
    assertEquals(1, run.getPassingTests().size());
    assertEquals(1, run.getRunningTests().size());
    assertEquals(0, run.getFailingTests().size());
    assertTrue(run.getFailingTests().isEmpty());
}
Also used : CtClass(spoon.reflect.declaration.CtClass) TestListener(fr.inria.stamp.test.listener.TestListener) Test(org.junit.Test)

Example 8 with TestListener

use of fr.inria.stamp.test.listener.TestListener in project dspot by STAMP-project.

the class TestLauncherTest method testOnMockito2.

@Test
public void testOnMockito2() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("src/test/resources/mockito2/target/"));
    } catch (Exception ignored) {
    }
    Utils.init("src/test/resources/mockito2/mock.properties");
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).buildClasspath(Utils.getInputProgram().getProgramDir()) + System.getProperty("path.separator") + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getClassesDir() + System.getProperty("path.separator") + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir();
    final CtClass<?> mockitoTest = Utils.findClass("org.baeldung.mocks.mockito.LoginControllerIntegrationTest");
    TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classpath, mockitoTest);
    assertEquals(7, run.getRunningTests().size());
    assertEquals(7, run.getPassingTests().size());
    assertEquals(0, run.getFailingTests().size());
}
Also used : TestListener(fr.inria.stamp.test.listener.TestListener) File(java.io.File) Test(org.junit.Test)

Example 9 with TestListener

use of fr.inria.stamp.test.listener.TestListener in project dspot by STAMP-project.

the class TestLauncherTest method testOnMockito.

@Test
public void testOnMockito() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("src/test/resources/mockito/target/"));
    } catch (Exception ignored) {
    }
    Utils.init("src/test/resources/mockito/mockito.properties");
    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(Utils.getInputConfiguration()).buildClasspath(Utils.getInputProgram().getProgramDir()) + System.getProperty("path.separator") + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getClassesDir() + System.getProperty("path.separator") + Utils.getInputProgram().getProgramDir() + "/" + Utils.getInputProgram().getTestClassesDir();
    final CtClass<?> mockitoTest = Utils.findClass("info.sanaulla.dal.BookDALTest");
    TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classpath, mockitoTest);
    assertEquals(5, run.getRunningTests().size());
    assertEquals(4, run.getPassingTests().size());
    assertEquals(1, run.getFailingTests().size());
}
Also used : TestListener(fr.inria.stamp.test.listener.TestListener) File(java.io.File) Test(org.junit.Test)

Example 10 with TestListener

use of fr.inria.stamp.test.listener.TestListener in project dspot by STAMP-project.

the class DefaultTestRunnerTest method testRunTestClass.

@Test
public void testRunTestClass() throws Exception {
    TestRunner runner = new DefaultTestRunner("src/test/resources/example-0.0.1-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT-tests.jar");
    TestListener results = runner.run("example.TestSuiteExample");
    assertEquals(8, results.getRunningTests().size());
    assertEquals(1, results.getFailingTests().size());
    assertEquals(6, results.getPassingTests().size());
    assertEquals(1, results.getAssumptionFailingTests().size());
    assertEquals(1, results.getIgnoredTests().size());
}
Also used : TestListener(fr.inria.stamp.test.listener.TestListener) Test(org.junit.Test)

Aggregations

TestListener (fr.inria.stamp.test.listener.TestListener)30 Test (org.junit.Test)20 IOException (java.io.IOException)8 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)7 File (java.io.File)7 Failure (org.junit.runner.notification.Failure)6 CtMethod (spoon.reflect.declaration.CtMethod)6 CtType (spoon.reflect.declaration.CtType)6 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)5 DSpotUtils (fr.inria.diversify.utils.DSpotUtils)5 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)5 TestCompiler (fr.inria.diversify.utils.compilation.TestCompiler)5 Collectors (java.util.stream.Collectors)5 Description (org.junit.runner.Description)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 CtClass (spoon.reflect.declaration.CtClass)5 Amplifier (fr.inria.diversify.dspot.amplifier.Amplifier)3 AssertGenerator (fr.inria.diversify.dspot.assertGenerator.AssertGenerator)3 TestSelector (fr.inria.diversify.dspot.selector.TestSelector)3