def _after_test_case_execution( self, test_case: tc.TestCase, result: res.ExecutionResult ) -> None: """Collect the execution trace after each executed test case.""" result.execution_trace = self._tracer.get_trace() for observer in self._observers: observer.after_test_case_execution(test_case, result)
def _collect_execution_trace(self, result: res.ExecutionResult): """ Collect the fitness after each execution. Also clear the tracking results so far. """ result.execution_trace = self._tracer.get_trace() self._tracer.clear_trace()
def test_compute_fitness_values(known_data_mock, executor_mock, trace_mock): tracer = MagicMock() tracer.get_known_data.return_value = known_data_mock executor_mock.tracer.return_value = tracer ff = BranchDistanceTestCaseFitnessFunction(executor_mock) indiv = MagicMock() with mock.patch.object(ff, "_run_test_case_chromosome") as run_suite_mock: result = ExecutionResult() result.execution_trace = trace_mock run_suite_mock.return_value = result assert ff.compute_fitness_values(indiv) == FitnessValues(0, 1) run_suite_mock.assert_called_with(indiv)
def test_compute_fitness_values_mocked(known_data_mock, executor_mock, trace_mock): tracer = MagicMock() tracer.get_known_data.return_value = known_data_mock executor_mock.tracer.return_value = tracer goal = MagicMock(bcg.AbstractBranchCoverageGoal) goal.get_distance.return_value = cfd.ControlFlowDistance(1, 2) ff = bctf.BranchCoverageTestFitness(executor_mock, goal) indiv = MagicMock() with mock.patch.object(ff, "_run_test_case_chromosome") as run_suite_mock: result = ExecutionResult() result.execution_trace = trace_mock run_suite_mock.return_value = result fitness_values = ff.compute_fitness_values(indiv) assert fitness_values.coverage == 0 assert pytest.approx(1.666666, fitness_values.fitness) run_suite_mock.assert_called_with(indiv)