0
我是新來的JUnit,以下this tutorial但需要在我的測試用例的一些建議和理解如何在eclipse中使用JUnit和groovy?
我有一個文件夾中的一些個XML(3MB-6MB個),每個XML我需要測試一些標記是否含有一些價值與否,有時會將該值與特定結果相匹配。
那麼如何在循環內執行我所有的@Test函數?我是否需要通常在循環內調用@Test函數(自動調用它們)?
請在此背景下幫助我學習JUnit。由於
Junit的TestCase的
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)
}
}