示例#1
0
def test_get_test_case_max_attempts():
    test_factory = MagicMock(tf.TestFactory)
    test_case_factory = tcf.RandomLengthTestCaseFactory(test_factory)
    test_case_factory.get_test_case()
    assert (
        test_factory.insert_random_statement.call_count == config.INSTANCE.max_attempts
    )
示例#2
0
def test_get_test_case_success():
    test_factory = MagicMock(tf.TestFactory)
    test_factory.insert_random_statement.side_effect = (
        lambda test_case, pos: test_case.add_statement(MagicMock(), 0))
    test_case_factory = tcf.RandomLengthTestCaseFactory(test_factory)
    test_case_factory.get_test_case()
    assert (1 <= test_factory.insert_random_statement.call_count <=
            config.INSTANCE.chromosome_length)
 def __init__(self, executor: TestCaseExecutor,
              test_cluster: TestCluster) -> None:
     super().__init__(executor, test_cluster)
     self._chromosome_factory = cf.TestSuiteChromosomeFactory(
         tcf.RandomLengthTestCaseFactory(self._test_factory))
     self._population: List[tsc.TestSuiteChromosome] = []
     self._selection_function: SelectionFunction[
         tsc.TestSuiteChromosome] = RankSelection()
     self._crossover_function: CrossOverFunction[
         tsc.TestSuiteChromosome] = SinglePointRelativeCrossOver()
     self._fitness_functions = self.get_fitness_functions()
示例#4
0
def test_seeded_test_case_factory_with_delegation(rand_mock,
                                                  clear_ips_instance,
                                                  seed_modules_path,
                                                  dummy_test_cluster):
    rand_mock.return_value = 2
    ips.initialpopulationseeding.test_cluster = dummy_test_cluster
    config.configuration.module_name = "primitiveseed"
    config.configuration.initial_population_seeding = True
    config.configuration.initial_population_data = seed_modules_path
    config.configuration.seeded_testcases_reuse_probability = 0.0
    ips.initialpopulationseeding.collect_testcases(seed_modules_path)
    test_factory = TestFactory(dummy_test_cluster)
    delegate = tcf.RandomLengthTestCaseFactory(test_factory)
    delegate.get_test_case = MagicMock()
    test_case_factory = tcf.SeededTestCaseFactory(delegate, test_factory)
    test_case_factory.get_test_case()
    delegate.get_test_case.assert_called_once()
示例#5
0
def test_seeded_test_case_factory_no_delegation(rand_mock, clear_ips_instance,
                                                seed_modules_path,
                                                dummy_test_cluster):
    rand_mock.return_value = 2
    ips.initialpopulationseeding.test_cluster = dummy_test_cluster
    config.configuration.module_name = "primitiveseed"
    config.configuration.initial_population_seeding = True
    config.configuration.initial_population_data = seed_modules_path
    config.configuration.seeded_testcases_reuse_probability = 1.0
    ips.initialpopulationseeding.collect_testcases(seed_modules_path)
    test_factory = TestFactory(dummy_test_cluster)
    delegate = tcf.RandomLengthTestCaseFactory(test_factory)
    test_case_factory = tcf.SeededTestCaseFactory(delegate, test_factory)

    seeded_testcase = test_case_factory.get_test_case()
    assert (next(iter(
        seeded_testcase.statements[2].assertions)).value == "Bools are equal!")
示例#6
0
    def _get_chromosome_factory(self) -> cf.ChromosomeFactory:
        """Provides a chromosome factory.

        Returns:
            A chromosome factory
        """
        # TODO add conditional returns/other factories here
        test_case_factory: tcf.TestCaseFactory = tcf.RandomLengthTestCaseFactory(
            self._test_factory
        )
        if config.configuration.initial_population_seeding:
            test_case_factory = tcf.SeededTestCaseFactory(
                test_case_factory, self._test_factory
            )
        test_case_chromosome_factory = tccf.TestCaseChromosomeFactory(
            self._test_factory, test_case_factory
        )
        if config.configuration.algorithm == config.Algorithm.MOSA:
            return test_case_chromosome_factory
        return tscf.TestSuiteChromosomeFactory(test_case_chromosome_factory)