Search in sources :

Example 1 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class RandomUserSystemTest method testRandom.

@Test
public void testRandom() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = RandomUser.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);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.INT_TYPE);
    boolean nextInt = purityAnalyzer.isPure(targetClass, "nextInt", descriptor);
    assertFalse(nextInt);
    boolean randomNextInt = purityAnalyzer.isPure(java.util.Random.class.getCanonicalName(), "nextInt", descriptor);
    assertFalse(randomNextInt);
    boolean secureRandomNextInt = purityAnalyzer.isPure(java.security.SecureRandom.class.getCanonicalName(), "nextInt", descriptor);
    assertFalse(secureRandomNextInt);
    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 : OutputVariable(org.evosuite.statistics.OutputVariable) CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 2 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class ImpureEqualsSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImpureEqualsTarget.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 3 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class ImpureJdkInspectorSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImpureJdkInspector.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.INT_TYPE);
    boolean getPureSize = purityAnalyzer.isPure(targetClass, "getPureSize", descriptor);
    assertTrue(getPureSize);
    boolean getImpureSize = purityAnalyzer.isPure(targetClass, "getImpureSize", descriptor);
    assertFalse(getImpureSize);
    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 4 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class InterfaceInspectorsSystemTest method testInterfaceInspectorCalls.

@Test
public void testInterfaceInspectorCalls() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = InterfaceInspectorCalls.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 pureInspector1 = purityAnalyzer.isPure(targetClass, "pureInspector1", descriptor);
    assertTrue(pureInspector1);
    boolean pureInspector2 = purityAnalyzer.isPure(targetClass, "pureInspector2", descriptor);
    assertTrue(pureInspector2);
    boolean impureInspector1 = purityAnalyzer.isPure(targetClass, "impureInspector1", descriptor);
    assertFalse(impureInspector1);
    boolean impureInspector2 = purityAnalyzer.isPure(targetClass, "impureInspector1", descriptor);
    assertFalse(impureInspector2);
    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 5 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class InterfaceInspectorsSystemTest method testInterfaceInspectorBuilder.

@Test
public void testInterfaceInspectorBuilder() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = InterfaceInspectorBuilder.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.INT_TYPE);
    String interfaceInspectorClassName = InterfaceInspector.class.getCanonicalName();
    boolean pureInspector = purityAnalyzer.isPure(interfaceInspectorClassName, "pureInspector", descriptor);
    assertTrue(pureInspector);
    boolean impureInspector = purityAnalyzer.isPure(interfaceInspectorClassName, "impureInspector", descriptor);
    assertFalse(impureInspector);
    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

CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)14 EvoSuite (org.evosuite.EvoSuite)13 OutputVariable (org.evosuite.statistics.OutputVariable)13 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)13 Test (org.junit.Test)13 AbstractInspector (com.examples.with.different.packagename.purity.AbstractInspector)1 AbstractToStringInspector (com.examples.with.different.packagename.purity.AbstractToStringInspector)1 PrintWriter (java.io.PrintWriter)1 CFGClassAdapter (org.evosuite.graphs.cfg.CFGClassAdapter)1 ErrorConditionClassAdapter (org.evosuite.instrumentation.error.ErrorConditionClassAdapter)1 BooleanTestabilityTransformation (org.evosuite.instrumentation.testability.BooleanTestabilityTransformation)1 ComparisonTransformation (org.evosuite.instrumentation.testability.ComparisonTransformation)1 ContainerTransformation (org.evosuite.instrumentation.testability.ContainerTransformation)1 StringTransformation (org.evosuite.instrumentation.testability.StringTransformation)1 ComputeClassWriter (org.evosuite.runtime.util.ComputeClassWriter)1 PrimitiveClassAdapter (org.evosuite.seeding.PrimitiveClassAdapter)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1 SerialVersionUIDAdder (org.objectweb.asm.commons.SerialVersionUIDAdder)1 ClassNode (org.objectweb.asm.tree.ClassNode)1