Search in sources :

Example 21 with TestListener

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

the class TestLauncherTest method testLauncherOnTestThatUseSystemProperties.

@Test
public void testLauncherOnTestThatUseSystemProperties() throws Exception {
    /*
			Contract: DSpot is able to run a test that use System Properties.
				System Properties must be described in the properties file given as input.
				System Properties must be described with the key systemProperties (i.e. systemProperties=...)
				System Properties must be a couple of key and value, separated by an equals '=' (e.g. key=value)
				System Properties must be separated by a comma ',' (e.g. key1=value1,key2=value2)

		 */
    Utils.init("src/test/resources/sample/sample.properties");
    final CtClass aClass = Utils.findClass("fr.inria.systemproperties.SystemPropertiesTest");
    final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputConfiguration());
    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 22 with TestListener

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

the class TestLauncherTest method testLauncherWithResources.

@Test
public void testLauncherWithResources() throws Exception {
    Utils.init("src/test/resources/project-with-resources/project-with-resources.properties");
    final CtClass aClass = Utils.findClass("resolver.ClasspathResolverTest");
    final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputConfiguration());
    final TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classPath, aClass);
    assertEquals(10, run.getPassingTests().size());
    assertEquals(10, run.getRunningTests().size());
    assertTrue(run.getFailingTests().isEmpty());
}
Also used : CtClass(spoon.reflect.declaration.CtClass) TestListener(fr.inria.stamp.test.listener.TestListener) Test(org.junit.Test)

Example 23 with TestListener

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

the class TestLauncherTest method testLauncherOnTestUsingReflectiveTestRunnerOnTestThatUseSystemProperty.

@Test
public void testLauncherOnTestUsingReflectiveTestRunnerOnTestThatUseSystemProperty() throws Exception {
    /*
			Using the ReflectiveTestRunner
		 */
    TestRunnerFactory.useReflectiveTestRunner = true;
    Utils.init("src/test/resources/sample/sample.properties");
    final CtClass aClass = Utils.findClass("fr.inria.systemproperties.SystemPropertiesTest");
    final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputConfiguration());
    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());
    TestRunnerFactory.useReflectiveTestRunner = false;
}
Also used : CtClass(spoon.reflect.declaration.CtClass) TestListener(fr.inria.stamp.test.listener.TestListener) Test(org.junit.Test)

Example 24 with TestListener

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

the class TestLauncherTest method testOnEasyMock.

@Test
public void testOnEasyMock() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("src/test/resources/easymock/target/"));
    } catch (Exception ignored) {
    }
    Utils.init("src/test/resources/easymock/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<?> easyMockTest = Utils.findClass("org.baeldung.mocks.easymock.LoginControllerIntegrationTest");
    TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classpath, easyMockTest);
    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 25 with TestListener

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

the class TestLauncherTest method testFromSpoonNodes.

@Test
public void testFromSpoonNodes() 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.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"), launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest").getMethodsByName("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.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("example.TestSuiteExample"), launcher.getFactory().Class().get("example.TestSuiteExample").getMethodsByName("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());
    // will use example.InheriteTest to run the test of AbstractTest
    results = TestLauncher.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"), launcher.getFactory().Class().get("example.AbstractTest").getMethodsByName("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());
}
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)

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