Example #1
0
    def test_generate_with_impact_analysis(self):
        tests_src = os.path.join(calculator_project_dir(), 'randoop')
        classes_dir = os.path.join(calculator_target_dir(), 'classes')

        randoop = Randoop(java=self.java,
                          classpath=classes_dir,
                          tests_src=tests_src,
                          sut_class='br.ufal.ic.easy.operations.Sum',
                          sut_classes=['br.ufal.ic.easy.operations.Sum'])
        randoop.parameters = [
            '--time-limit=1', '--testclass=br.ufal.ic.easy.operations.Sum'
        ]

        safira = Safira(self.java, classes_dir, calculator_src_aor_1())

        (suite_name, suite_dir, suite_classes_dir,
         suite_classes) = randoop.generate_with_impact_analysis(safira)

        self.assertTrue(suite_name.startswith('randoop'))
        self.assertTrue(os.path.exists(suite_dir))

        self.assertTrue(len(get_java_files(suite_dir)) > 1)
        self.assertTrue(len(get_class_files(suite_classes_dir)) > 1)
        self.assertEquals(2, len(suite_classes))

        shutil.rmtree(tests_src)
Example #2
0
    def test_generate_differential(self):

        tests_src = os.path.join(calculator_project_dir(), 'evosuite')

        evosuite = Evosuite(java=self.java,
                            classpath=os.path.join(calculator_target_dir(),
                                                   'classes'),
                            tests_src=tests_src,
                            sut_class='br.ufal.ic.easy.operations.Sum',
                            params=['-Dsearch_budget=1'])

        mutants = MuJava(java=self.java,
                         mutants_dir=calculator_mutants_dir()).read_log()

        (suite_name, suite_dir, suite_classes_dir,
         suite_classes) = evosuite.generate_differential(mutants[1].dir)

        self.assertTrue(suite_name.startswith('evosuite'))
        self.assertTrue(os.path.exists(suite_dir))

        self.assertTrue(len(get_java_files(suite_dir)) > 1)
        self.assertTrue(len(get_class_files(suite_classes_dir)) > 1)
        self.assertEquals(1, len(suite_classes))

        shutil.rmtree(tests_src)
    def generate_suite(java, tests_src, sut_class):
        randoop = Randoop(
            java=java,
            classpath=os.path.join(calculator_target_dir(), 'classes'),
            tests_src=tests_src,
            sut_class=sut_class
        )
        randoop.parameters = ['--time-limit=1']

        return randoop.generate()
Example #4
0
    def generate_suite(java, tests_src, sut_class):
        randoop = Randoop(java=java,
                          classpath=os.path.join(calculator_target_dir(),
                                                 'classes'),
                          tests_src=tests_src,
                          sut_class=sut_class,
                          sut_classes=[sut_class])
        randoop.parameters = [
            '--time-limit=1', '--testclass=br.ufal.ic.easy.operations.Sum'
        ]

        return randoop.generate()
    def test_get_class_files(self):
        classes = get_class_files(calculator_target_dir())

        self.assertEqual(6, len(classes))
        self.assertTrue('classes/br/ufal/ic/easy/Calculator.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Sum.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Operation.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Div.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Sub.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Mul.class' in classes)
Example #6
0
    def setUpClass(cls):
        cls.java_home = get_config()['java_home']
        cls.maven_home = get_config()['maven_home']

        cls.java = Java(cls.java_home)
        cls.maven = Maven(cls.java, cls.maven_home)

        cls.maven.compile(calculator_project_dir(), 10)

        cls.classpath = os.path.join(calculator_target_dir(), 'classes')
        cls.tests_src = os.path.join(calculator_project_dir(), 'randoop')
        cls.sut_class = 'br.ufal.ic.easy.operations.Sum'

        (cls.suite_name, cls.suite_dir, cls.suite_classes_dir,
         cls.suite_classes) = cls.generate_suite(cls.java, cls.tests_src,
                                                 cls.sut_class)
Example #7
0
    def test_run_safira(self):
        safira = Safira(self.java, calculator_target_dir(),
                        calculator_src_aor_1())

        results = safira.run()

        self.assertEqual(3, len(results.methods))
        self.assertTrue('br.ufal.ic.easy.operations.Sum.impacted(int, int)' in
                        results.methods)
        self.assertTrue('br.ufal.ic.easy.operations.Sum.execute(int, int)' in
                        results.methods)
        self.assertTrue(
            'br.ufal.ic.easy.Calculator.sum(int, int)' in results.methods)
        self.assertEqual(2, len(results.constructors))
        self.assertTrue('br.ufal.ic.easy.Calculator()' in results.constructors)
        self.assertTrue(
            'br.ufal.ic.easy.operations.Sum()' in results.constructors)
    def test_get_files(self):
        classes = get_files(calculator_target_dir())

        self.assertEqual(8, len(classes))
        self.assertTrue(('maven-status/maven-compiler-plugin/compile/' +
                         'default-compile/inputFiles.lst') in classes)
        self.assertTrue(('maven-status/maven-compiler-plugin/compile/' +
                         'default-compile/createdFiles.lst') in classes)
        self.assertTrue('classes/br/ufal/ic/easy/Calculator.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Sum.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Operation.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Div.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Sub.class' in classes)
        self.assertTrue(
            'classes/br/ufal/ic/easy/operations/Mul.class' in classes)
Example #9
0
    def test_generate(self):

        tests_src = os.path.join(calculator_project_dir(), 'randoop')

        randoop = Randoop(java=self.java,
                          classpath=os.path.join(calculator_target_dir(),
                                                 'classes'),
                          tests_src=tests_src,
                          sut_class='br.ufal.ic.easy.operations.Sum')
        randoop.parameters = ['--time-limit=1']

        (suite_name, suite_dir, suite_classes_dir,
         suite_classes) = randoop.generate()

        self.assertTrue(suite_name.startswith('randoop'))
        self.assertTrue(os.path.exists(suite_dir))

        self.assertTrue(len(get_java_files(suite_dir)) > 1)
        self.assertTrue(len(get_class_files(suite_classes_dir)) > 1)
        self.assertEquals(1, len(suite_classes))
Example #10
0
    def test_run_safira_timeout(self):
        safira = Safira(self.java, calculator_target_dir(),
                        calculator_src_aor_1())

        with self.assertRaises(subprocess.TimeoutExpired):
            safira.run(timeout=0)