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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations