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