Search in sources :

Example 56 with OutputVariable

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

the class RandomUUIDSystemTest method testRandomUUID.

@Test
public void testRandomUUID() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = RandomUUIDUser.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)

Example 57 with OutputVariable

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

the class CoverageAnalysisOfEvoSuiteTestSuiteSystemTest method testOneFitnessFunction.

@Test
public void testOneFitnessFunction() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Euclidean.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + targetClass + Properties.JUNIT_SUFFIX, "-measureCoverage" };
    SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);
    Map<String, OutputVariable<?>> data = statistics.getOutputVariables();
    assertEquals(5, (Integer) data.get("Total_Goals").getValue(), 0.0);
    assertEquals(5, (Integer) data.get("Covered_Goals").getValue(), 0.0);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 58 with OutputVariable

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

the class JUnitOnSeparateProcessPropertySystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Foo.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);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class));
    boolean equals = purityAnalyzer.isPure(targetClass, "equals", descriptor);
    assertFalse(equals);
    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 : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 59 with OutputVariable

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

the class ToStringInspectorSystemTest method testPureToString.

@Test
public void testPureToString() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ToStringInspector.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);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.getType(String.class));
    boolean toString = purityAnalyzer.isPure(targetClass, "toString", descriptor);
    assertFalse(toString);
    boolean abstractToString = purityAnalyzer.isPure(AbstractToStringInspector.class.getCanonicalName(), "toString", descriptor);
    assertFalse(abstractToString);
    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 : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) AbstractToStringInspector(com.examples.with.different.packagename.purity.AbstractToStringInspector) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 60 with OutputVariable

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

the class JdkInspectorSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = JdkPureInspector.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);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.BOOLEAN_TYPE);
    boolean equalsToZ = purityAnalyzer.isPure(targetClass, "equalsToZ", descriptor);
    assertTrue(equalsToZ);
    boolean isLowerCase = purityAnalyzer.isPure(targetClass, "isLowerCase", descriptor);
    assertTrue(isLowerCase);
    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 : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) 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