Search in sources :

Example 6 with OutputVariable

use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.

the class CarverSystemTest method testPublicStaticField.

@Test
public void testPublicStaticField() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Days.class.getCanonicalName();
    // Test suite with private static field.
    String testClass = TestDaysWithPublicField.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("Coverage");
    Assert.assertEquals("Non-optimal coverage", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 7 with OutputVariable

use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.

the class CarverSystemTest method testPrivateStaticField.

// There doesn't seem to be an easy solution to this so let's ignore it for now
@Ignore
@Test
public void testPrivateStaticField() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Days.class.getCanonicalName();
    // Test suite with private static field.
    String testClass = TestDays.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("Coverage");
    Assert.assertEquals("Non-optimal coverage", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with OutputVariable

use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.

the class CarverSystemTest method testJodaTestScaledDurationFieldWithException.

// An exception is thrown in the constructor. There is nothing that can be carved...
@Ignore
@Test
public void testJodaTestScaledDurationFieldWithException() {
    EvoSuite evosuite = new EvoSuite();
    // TestScaledDurationField.test_constructor causes NoSuchMethodException,
    // possibly related to a super() call in ScaledDurationField's constructor
    String targetClass = ScaledDurationField.class.getCanonicalName();
    String testClass = TestScaledDurationFieldWithException.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.PRINT_GOALS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    Properties.GLOBAL_TIMEOUT = 600;
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("MethodCoverage");
    Assert.assertEquals("Non-optimal method coverage value", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with OutputVariable

use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.

the class StaticSingletonFieldSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = SaticSingletonField.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals("Unexpected unstabled test cases were generated", Boolean.FALSE, unstable.getValue());
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 10 with OutputVariable

use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.

the class ResetOrderSystemTest method testResetOrder.

@Test
public void testResetOrder() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ResetOrderClassA.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Aggregations

OutputVariable (org.evosuite.statistics.OutputVariable)71 Test (org.junit.Test)67 EvoSuite (org.evosuite.EvoSuite)61 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)49 SearchStatistics (org.evosuite.statistics.SearchStatistics)19 Properties (org.evosuite.Properties)18 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 CalculatorTest (com.examples.with.different.packagename.CalculatorTest)2 Ignore (org.junit.Ignore)2 ClassHierarchyIncludingInterfacesTest (com.examples.with.different.packagename.ClassHierarchyIncludingInterfacesTest)1 ClassNumberUtilsTest (com.examples.with.different.packagename.ClassNumberUtilsTest)1 ClassPublicInterfaceTest (com.examples.with.different.packagename.ClassPublicInterfaceTest)1 ClassWithPrivateInterfacesTest (com.examples.with.different.packagename.ClassWithPrivateInterfacesTest)1 FinalClassTest (com.examples.with.different.packagename.FinalClassTest)1 StringUtilsEqualsIndexOfTest (com.examples.with.different.packagename.StringUtilsEqualsIndexOfTest)1 WordUtilsTest (com.examples.with.different.packagename.WordUtilsTest)1 AbstractInspector (com.examples.with.different.packagename.purity.AbstractInspector)1 AbstractToStringInspector (com.examples.with.different.packagename.purity.AbstractToStringInspector)1