The tester’s Test Technical Manual: a pit and the method of pit filling for the intelligent test framework EvoSuite

The problem

Recently, while constantly learning and exploring EvoSuite framework, the following problems occurred after the production of JUnit unit test framework:

Exception: under Caused by: org. Evosuite. Runtime. TooManyResourcesException: Loop has had been executed moretimes than the allowed 10000
at org.evosuite.runtime.LoopCounter.checkLoop(LoopCounter.java:115)
at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at org.apache.poi.util.DocumentHelper.readDocument(DocumentHelper.java:137)
at org.apache.poi.POIXMLTypeLoader.parse(POIXMLTypeLoader.java:115)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:203)
at org.apache.poi.xssf.model.StylesTable.(StylesTable.java:146)
Copy the code

Analysis and revision

All EvoSuite generated unit test classes inherit from scaffolding classes of the same name, in the @beforeClass section of the corresponding scaffold suffix class, with one argument:

Org. Evosuite. Runtime. RuntimeSettings. MaxNumberOfIterationPerLoop = 10000;Copy the code

The above error is caused by the setting of this item. Then the org. Evosuite. Runtime. RuntimeSettings. MaxNumberOfIterationPerLoop is stem what of? Here we go to the EvoSuite source code.

After source code analysis, in the source code:

evosuite/runtime/src/main/java/org/evosuite/runtime/LoopCounter.java
Copy the code

It is found that lines 110 to 123 can throw the corresponding exception. According to the author’s comment, this class is specially made to avoid the occurrence of infinite loops. The location of the source code can be seen as an exception thrown by a code that has executed more than 10,000 times. Such a large number of loops can be caused by mock data or internal script logic exceptions.

Solve the problem

Through the search of corresponding Github project, it is found that this is not a fixed issue. However, you can set this parameter to avoid this exception. Through maxNumberOfIterationPerLoop appear the condition part of the judgment: evosuite/runtime/SRC/main/Java/org/evosuite/runtime/LoopCounter. Java’s 96 to 98 lines, as follows:

 if(RuntimeSettings.maxNumberOfIterationsPerLoop < 0){
            return; //do nothing, no check
        }
Copy the code

And/Users/chancriss/Desktop/WorkSpace/JavaSpace/lot/evosuite/runtime/SRC/main/Java/org/evosuite/runtime/instrumentation / RuntimeInstrumentation lines 144 to 146, under the Java is as follows:

	if (RuntimeSettings.maxNumberOfIterationsPerLoop >= 0) {
			cv = new LoopCounterClassAdapter(cv);
		}
Copy the code

, to avoid the occurrence of this kind of problem, not the corresponding JUnit script in the parent class expand org. Evosuite. Runtime. RuntimeSettings. MaxNumberOfIterationPerLoop values, but it is set to become a value less than 0.

Since testers do not fully grasp the framework, the exact consequences of this modification have not been further studied.

Focus on the tester, focus on the test