Search in sources :

Example 26 with OutputVariable

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

the class PublicFieldSystemTest method testPrimitiveFieldClass.

@Test
public void testPrimitiveFieldClass() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassWithPublicPrimitiveField.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    Properties.MINIMIZE = false;
    Properties.ASSERTION_STRATEGY = Properties.AssertionStrategy.ALL;
    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 27 with OutputVariable

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

the class ToStringInspectorSystemTest method testImpureToString.

@Test
public void testImpureToString() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImpureToStringInspector.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);
    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 28 with OutputVariable

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

the class Base64SystemTest method testBase64.

@Test
public void testBase64() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Base64.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 29 with OutputVariable

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

the class ArrayDefaultSystemTest method testIntegerDefault.

@Test
public void testIntegerDefault() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = IntegerArrayDefault.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 30 with OutputVariable

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

the class CoverageAnalysisOfClassSystemTest method testMeasureCoverageOfCarvedTests.

@Test
public void testMeasureCoverageOfCarvedTests() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MethodWithSeveralInputArguments.class.getCanonicalName();
    String testClass = TestMethodWithSeveralInputArguments.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.INPUT, Properties.Criterion.METHOD, Properties.Criterion.OUTPUT };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable<?> methodCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.MethodCoverage.name());
    OutputVariable<?> inputCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.InputCoverage.name());
    OutputVariable<?> outputCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.OutputCoverage.name());
    Assert.assertEquals("Unexpected method coverage value", 1d, (Double) methodCoverage.getValue(), 0.01);
    Assert.assertEquals("Unexpected input coverage value", 0.67d, (Double) inputCoverage.getValue(), 0.01);
    Assert.assertEquals("Unexpected output coverage value", 0.33d, (Double) outputCoverage.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) CalculatorTest(com.examples.with.different.packagename.CalculatorTest)

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