def generate_sequence( self, test_chromosome: tsc.TestSuiteChromosome, failing_test_chromosome: tsc.TestSuiteChromosome, execution_counter: int, ) -> None: """Implements one step of the adapted Randoop algorithm. Args: test_chromosome: The list of currently successful test cases failing_test_chromosome: The list of currently not successful test cases execution_counter: A current number of algorithm iterations Raises: GenerationException: In case an error occurs during generation """ self._logger.info("Algorithm iteration %d", execution_counter) timer = Timer(name="Sequence generation", logger=None) timer.start() objects_under_test: Set[ gao. GenericAccessibleObject] = self.test_cluster.accessible_objects_under_test if not objects_under_test: # In case we do not have any objects under test, we cannot generate a # test case. raise GenerationException( "Cannot generate test case without an object-under-test!") # Create new test case, i.e., sequence in Randoop paper terminology # Pick a random public method from objects under test method = self._random_public_method(objects_under_test) # Select random test cases from existing ones to base generation on tests = self._random_test_cases(test_chromosome.test_chromosomes) new_test: tc.TestCase = dtc.DefaultTestCase() for test in tests: new_test.append_test_case(test) # Generate random values as input for the previously picked random method # Extend the test case by the new method call self.test_factory.append_generic_statement(new_test, method) # Discard duplicates if (new_test in test_chromosome.test_chromosomes or new_test in failing_test_chromosome.test_chromosomes): return with Timer(name="Execution time", logger=None): # Execute new sequence exec_result = self._executor.execute([new_test]) # Classify new test case and outputs if exec_result.has_test_exceptions(): failing_test_chromosome.add_test(new_test) else: test_chromosome.add_test(new_test) # TODO(sl) What about extensible flags? self._execution_results.append(exec_result) timer.stop()
def raise_exception(*args): raise GenerationException("Exception Test")
def test_raise_test_generation_exception_with_message(): with pytest.raises(GenerationException) as exception: raise GenerationException("foo") assert exception.value.args[0] == "foo"
def test_raise_test_generation_exception(): with pytest.raises(GenerationException): raise GenerationException()