import groovy.util.slurpersupport.Node
import groovy.util.slurpersupport.NodeChild
/**
* Created by on 2017-03-25.
*/
File file = new File("/Users/zaid/output/1")
XMLLoader xmlLoader = new XMLLoader(file);
HashMap<String, XmlSlurper> temp = xmlLoader.sendNodes()
JunitDataParser junitParser = new JunitDataParser(temp)
junitParser.populateStats()
public class XMLLoader {
HashMap<String, XmlSlurper> rootNodes; // Collection of root nodes for Junit xml files
public XMLLoader(File junitFile) {
rootNodes = new ArrayList<>()
// If file is directory then closure will search directory to find valid xml files
if (junitFile.isDirectory()) {
junitFile.eachFile {
if (validateFile(it)) {
rootNodes.put(it.name, new XmlSlurper().parse(it)) // Load each fine into arraylist of XMLSlurpers
}
}
} else {
if (validateFile(junitFile)) {
rootNodes.put(junitFile.name, new XmlSlurper().parse(it))
// Load single fine into arraylist of XMLSlurpers
}
}
}
boolean validateFile(File checkFile) {
if (checkFile.name.endsWith('.xml')) {
assert checkFile.exists(): "The file entered could not be be read"
assert checkFile.canRead(): "The file entered could not be be read"
return true;
}
return false
}
HashMap<String, XmlSlurper> sendNodes() {
return rootNodes
}
}
public class JunitDataParser extends GeneralDataParser {
def JunitDataParser(HashMap<String, XmlSlurper> rootNodes) {
super(rootNodes)
}
HashMap<String, ArrayList<TestSuites>> getPopulatedData() {
return super.getPopulatedData()
}
void populateStats() {
ArrayList<TestSuite> stats = getTestSuites();
}
ArrayList<TestSuite> getTestSuites() {
ArrayList<TestSuite> testSuites = new ArrayList<>()
rootNodes.get("first.xml").'**'.findAll {
(it.name().equals("testsuite")) && (it.children().getAt(0).name().equals("testcase"))
}.each {
TestSuite temp = new TestSuite(it.attributes().get("name"), it.attributes().get("tests").toInteger(), it.attributes().get("errors").toInteger(), it.attributes().get("time"), it.attributes().get("timestamp"), getTestCases(it))
testSuites.add(temp)
}
return testSuites
}
ArrayList<TestCase> getTestCases(NodeChild testSuiteNode) {
ArrayList<TestCase> testCases = new ArrayList<>()
testSuiteNode.childNodes().each {
String time;
if (time!=null && time.length()>0) {
time = it.attributes().get("time")
} else {
time = "Time Not Found"
}
testCases.add(new TestCase(it.attributes().get("name"), getOutCome(it), time))
}
return testCases
}
TestResult getOutCome(Node testCaseNode) {
String testMessage = "hi"
int testOutcome = 0;
if (testCaseNode.childNodes().size() != 0) {
testCaseNode.childNodes().each {
it.attributes().each {
testMessage = testMessage + "\n $it.key : $it.value"
}
}
testOutcome =1
}
TestResult temp = new TestResult(0,testMessage)
return temp
}
}
// The Base abstract class that all additional parsers should extend and populate
public abstract class GeneralDataParser {
HashMap<String, XmlSlurper> rootNodes
HashMap<String, ArrayList<TestSuites>> populatedData
public GeneralDataParser(HashMap<String, XmlSlurper> rootNodes) {
this.rootNodes = rootNodes
}
abstract void populateStats()
abstract ArrayList<TestSuite> getTestSuites()
abstract ArrayList<TestCase> getTestCases(NodeChild testSuiteNodes)
abstract TestResult getOutCome(Node testCaseNode)
}
public class TestSuites {
ArrayList<TestSuite> testSuites
TestSuites(ArrayList<TestSuite> testSuites) {
this.testSuites = testSuites
}
}
public class TestSuite {
String testSuiteName
int numOfTests
int numOfErrors
int numOfFailures
String timeTaken;
String timeStamp;
ArrayList<TestCase> testCases
TestSuite(String testSuiteName, int numOfTests, int numOfErrors, int numOfFailures, String timeTaken, String timeStamp, ArrayList<TestCase> testCases) {
this.testSuiteName = testSuiteName
this.numOfTests = numOfTests
this.numOfErrors = numOfErrors
this.numOfFailures = numOfFailures
this.timeTaken = timeTaken
this.timeStamp = timeStamp
this.testCases = testCases
}
}
public class TestCase {
String testCasename
TestResult testOutcome
String testCaseTime = ""
TestCase(String testCasename, TestResult testOutcome, String testCaseTime) {
this.testCasename = testCasename
this.testOutcome = testOutcome
this.testCaseTime = testCaseTime
}
}
public class TestResult {
int valOfResult
String textOfResult
TestResult(int valOfResult, String textOfResult) {
this.valOfResult = valOfResult
this.textOfResult = textOfResult
}
}
我一直找不到匹配的构造函数,任何人都可以看到任何问题吗?
抓住:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:TestSuite(java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.String,java.lang.String, java.util.ArrayList中) groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:TestSuite(java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.String,java.lang.String,java.util.ArrayList ) 在JunitDataParser $ _getTestSuites_closure2.doCall(JunitXMLToBeautifulHTML.groovy:70) 在JunitDataParser.getTestSuites(JunitXMLToBeautifulHTML.groovy:67) 在JunitDataParser.populateStats(JunitXMLToBeautifulHTML.groovy:62) 在JunitDataParser $ populateStats.call(未知来源) 在JunitXMLToBeautifulHTML.run(JunitXMLToBeautifulHTML.groovy:13) 在com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
答案 0 :(得分:0)
错误消息是正确的。
构造函数的签名是:
TestSuite(String testSuiteName, int numOfTests, int numOfErrors, int numOfFailures, String timeTaken, String timeStamp, ArrayList<TestCase> testCases)
你正试图使用:
new TestSuite(it.attributes().get("name"), it.attributes().get("tests").toInteger(), it.attributes().get("errors").toInteger(), it.attributes().get("time"), it.attributes().get("timestamp"), getTestCases(it))
所以你没有传递numOfFailures
。