/** * Evaluates the test case to define if test generation has reached a plateau. The test case * generation is considered to have reached a plateau if the current test case is observed to gain * less than the plateau threshold of added coverage in the current best exploration option (up to * 'depth' new steps). The plateau threshold is defined in the exploration configuration. * * @param suite The suite where we grab the current test from to check for plateau. * @param steps How many steps to check for the plateau. * @return True if plateau is reached. False otherwise. */ private boolean isTestPlateau(TestSuite suite, int steps) { TestCase currentTest = suite.getCurrentTest(); int length = currentTest.getSteps().size(); // steps + 1 is to measure gain for last "steps" number of steps correctly // for example, suite has four steps: A,B,C,D and we request to look at last 3 // if we count different between D and B, we get gain of last two which is C and D // so we must look at different between gain in end of A and in end of D. this requires the + 1 int index = length - (steps + 1); if (index < steps) { // not possible to check the plateau if test is not long enough return false; } int now = currentTest.getCurrentStep().getAddedCoverage(); int before = currentTest.getSteps().get(index).getAddedCoverage(); // TestCoverage coverage = suite.getCoverage(); // int now = scoreCalculator.addedScoreFor(coverage, currentTest); //// int before = scoreCalculator.addedScoreFor(coverage, currentTest, length-steps); // int before = scoreCalculator.addedScoreFor(coverage, currentTest); int diff = now - before; // is the added value more than the given threshold? return diff < config.getTestPlateauThreshold(); }