Search in sources :

Example 1 with Project

use of org.evosuite.xsd.Project in project evosuite by EvoSuite.

the class StorageManager method mergeAndCommitChanges.

/**
 * Compare the results of this CTG run with what was in
 * the database. Keep/update the best results.
 *
 * @param
 * @return
 */
public String mergeAndCommitChanges(ProjectStaticData current, String[] cuts) throws NullPointerException {
    if (current == null) {
        throw new NullPointerException("ProjectStaticData 'current' cannot be null");
    }
    Project db = StorageManager.getDatabaseProject();
    String info = "\n\n=== CTG run results ===\n";
    info += removeNoMoreExistentData(db, current);
    List<TestsOnDisk> suites = gatherGeneratedTestsOnDisk();
    info += "\nNew test suites: " + suites.size();
    // identify for which CUTs we failed to generate tests
    Set<String> missingCUTs = new LinkedHashSet<String>();
    db.setTotalNumberOfTestableClasses(BigInteger.valueOf(current.getTotalNumberOfTestableCUTs()));
    for (String cut : current.getClassNames()) {
        if (!current.getClassInfo(cut).isTestable()) {
            // of that class. and not even counting it as a missing class
            continue;
        }
        TestsOnDisk suite = suites.parallelStream().filter(s -> s.cut.equals(cut)).findFirst().orElse(null);
        if (suite == null && current.getClassInfo(cut).isToTest()) {
            missingCUTs.add(cut);
        }
        LoggingUtils.getEvoLogger().info("* Updating database to " + cut);
        updateDatabase(cut, suite, db, current);
    }
    if (!missingCUTs.isEmpty()) {
        if (missingCUTs.size() == 1) {
            info += "\n\nWARN: failed to generate tests for " + missingCUTs.iterator().next();
        } else {
            info += "\n\nMissing classes:";
            for (String missingCUT : missingCUTs) {
                info += "\n" + missingCUT;
            }
            String summary = "\n\nWARN: failed to generate tests for " + missingCUTs.size() + " classes out of " + current.getTotalNumberOfTestableCUTs();
            info += summary;
        }
    }
    commitDatabase(db);
    return info;
}
Also used : Project(org.evosuite.xsd.Project)

Example 2 with Project

use of org.evosuite.xsd.Project in project evosuite by EvoSuite.

the class ContinuousTestGeneration method info.

/**
 * Get info on the current test cases in the database
 * @return
 */
public String info() {
    Project project = StorageManager.getDatabaseProject();
    if (project == null) {
        return "No info available";
    }
    // TODO all info
    StringBuilder sb = new StringBuilder();
    sb.append("Total number of classes in the project: " + ProjectUtil.getNumberTestableClasses(project) + "\n");
    sb.append("Number of classes in the project that are testable: " + ProjectUtil.getNumberTestableClasses(project) + "\n");
    sb.append("Number of generated test suites: " + ProjectUtil.getNumberGeneratedTestSuites(project) + "\n");
    sb.append("Overall coverage: " + ProjectUtil.getOverallCoverage(project) + "\n");
    return sb.toString();
}
Also used : Project(org.evosuite.xsd.Project)

Example 3 with Project

use of org.evosuite.xsd.Project in project evosuite by EvoSuite.

the class ProjectStaticDataTest method testIsToTest_NoData.

@Test
public void testIsToTest_NoData() {
    Project project = new Project();
    project.setTotalNumberOfTestableClasses(XSDUtils.convert(0));
    // there is not any data at all
    Assert.assertTrue(new ProjectStaticData().isToTest("foo.Bar", 3));
}
Also used : Project(org.evosuite.xsd.Project) Test(org.junit.Test)

Example 4 with Project

use of org.evosuite.xsd.Project in project evosuite by EvoSuite.

the class ProjectStaticDataTest method testIsToTest_SkippedClass.

@Test
public void testIsToTest_SkippedClass() {
    Project project = new Project();
    project.setTotalNumberOfTestableClasses(XSDUtils.convert(1));
    CUT cut = new CUT();
    cut.setFullNameOfTargetClass("foo.Bar");
    cut.setFullNameOfTestSuite("foo.BarTest");
    Generation g0 = new Generation();
    g0.setId(XSDUtils.convert(0));
    g0.setFailed(false);
    g0.setModified(true);
    g0.setTimeBudgetInSeconds(XSDUtils.convert(60));
    // empty dummy test suite
    g0.setSuite(new TestSuite());
    // and add first generation
    cut.getGeneration().add(g0);
    for (int i = 1; i <= 3; i++) {
        Generation g = new Generation();
        g.setId(XSDUtils.convert(i));
        g.setFailed(false);
        g.setModified(false);
        g.setTimeBudgetInSeconds(XSDUtils.convert(60));
        // and no test suite
        cut.getGeneration().add(g);
    }
    Generation g4 = new Generation();
    g4.setId(XSDUtils.convert(4));
    g4.setFailed(false);
    g4.setModified(false);
    // EvoSuite skipped this one
    g4.setTimeBudgetInSeconds(XSDUtils.convert(0));
    cut.getGeneration().add(g4);
    project.getCut().add(cut);
    ProjectStaticData data = new ProjectStaticData();
    data.setProject(project);
    // coverage has not improved
    Assert.assertFalse(data.isToTest("foo.Bar", 3));
}
Also used : Project(org.evosuite.xsd.Project) Generation(org.evosuite.xsd.Generation) CUT(org.evosuite.xsd.CUT) TestSuite(org.evosuite.xsd.TestSuite) Test(org.junit.Test)

Example 5 with Project

use of org.evosuite.xsd.Project in project evosuite by EvoSuite.

the class ProjectStaticDataTest method testIsToTest_NotEnoughGenerations.

@Test
public void testIsToTest_NotEnoughGenerations() {
    Project project = new Project();
    project.setTotalNumberOfTestableClasses(XSDUtils.convert(1));
    CUT cut = new CUT();
    cut.setFullNameOfTargetClass("foo.Bar");
    cut.setFullNameOfTestSuite("foo.BarTest");
    Generation generation = new Generation();
    cut.getGeneration().add(generation);
    project.getCut().add(cut);
    ProjectStaticData data = new ProjectStaticData();
    data.setProject(project);
    // not enough data to compare, re-test it
    Assert.assertTrue(data.isToTest("foo.Bar", 3));
}
Also used : Project(org.evosuite.xsd.Project) Generation(org.evosuite.xsd.Generation) CUT(org.evosuite.xsd.CUT) Test(org.junit.Test)

Aggregations

Project (org.evosuite.xsd.Project)11 Test (org.junit.Test)8 CUT (org.evosuite.xsd.CUT)5 Generation (org.evosuite.xsd.Generation)5 TestSuite (org.evosuite.xsd.TestSuite)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1