我是 JUnit 的新手,遵循本教程,但需要对我的测试用例提出一些建议和理解
我在一个文件夹中有一些 xml(每个 3MB-6MB),对于每个 xml,我需要测试一些标签是否包含某些值,有时将该值与特定结果匹配。
那么,对于每个测试,如何在循环内执行所有 @Test 函数呢?我是否需要在循环内正常调用 @Test 函数(因为它们是自动调用的)?
请帮助我在这种情况下理解 JUnit。谢谢
Junit 测试用例
public class SystemsCheck {
def fileList
@Before
public void setUp() throws Exception {
def dir = new File("E:\\temp\\junit\\fast")
fileList = []
def newFile=""
dir.eachFileRecurse (FileType.FILES) { file ->
fileList << file
}
fileList.each {
//how should i test all @Test with it.text
println it.text
}
}
@Test
void testOsname(){
NixSystems ns=new NixSystems()
/*checking if tag is not empty*/
//assertEquals("Result","",ns.verifyOsname())
}
@Test
public void testMultiply(){
NixSystems ns=new NixSystems()
assertEquals("Result", 50, ns.multiply(10, 5))
}
}
class NixSystems {
public def verifyOsname(xml){
return processXml( xml, '//client/system/osname' )
}
public def multiply(int x, int y) {
return x * y;
}
def processXml( String xml, String xpathQuery ) {
def xpath = XPathFactory.newInstance().newXPath()
def builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
def inputStream = new ByteArrayInputStream( xml.bytes )
def records = builder.parse(inputStream).documentElement
xpath.evaluate( xpathQuery, records )
}
}