详细Hudson测试报告

时间:2011-01-11 14:42:25

标签: testing hudson

有没有办法强迫哈德森给我更详细的测试结果 - 例如我正在比较两个字符串,我想知道它们的不同之处。 有没有办法做到这一点? 谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

你不应该希望Hudson提供详细信息,它只显示junit生成的测试消息。

当失败的断言等于这两个字符串之间时,您可以显示预期的字符串和实际字符串。

例如,

protected void compareFiles(File newFile, String referenceLocation, boolean lineNumberMatters) {
    BufferedReader reader = null;
    BufferedReader referenceReader = null;
    List<String> expectedLines = new ArrayList<String>();
    try {
        referenceReader = new BufferedReader(new InputStreamReader(FileLocator.openStream(Activator.getDefault().getBundle(), new Path("data/regression/" + referenceLocation), false)));  //$NON-NLS-1$
        expectedLines = getLinesFromReader(referenceReader);
    } catch (Exception e) {
        assertFalse("Exception occured during reading reference data: " + e, true); //$NON-NLS-1$
    }
    List<String>foundLines = new ArrayList<String>();
    try {
        reader = new BufferedReader(new FileReader(newFile));
        foundLines = getLinesFromReader(reader);
    } catch (Exception e) {
        assertFalse("Exception occured during reading file: " + e, true); //$NON-NLS-1$
    }
    boolean throwException = expectedLines.size() != foundLines.size();
    if (throwException) {
        StringBuffer buffer = new StringBuffer("\n" + newFile.toString()); //$NON-NLS-1$
        for (String line: foundLines)
            buffer.append(line + "\n"); //$NON-NLS-1$
        assertEquals("The number of lines in the reference(" + referenceLocation + ") and new output(" + newFile.getAbsolutePath()+ ") did not match!" + buffer, expectedLines.size(), foundLines.size()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    if (!lineNumberMatters) {
        Collections.sort(expectedLines);
        Collections.sort(foundLines);
    }
    /** Either the line matches character by character or it matches regex-wise, in that order */
    for (int i=0;i<expectedLines.size(); i++)
        assertTrue("Found errors in file (" + newFile + ")! " + foundLines.get(i) + " vs. " + expectedLines.get(i), foundLines.get(i).equals(expectedLines.get(i)) || foundLines.get(i).matches(expectedLines.get(i))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

答案 1 :(得分:0)

Hudson直接支持JUnit。在您的作业配置页面上,接近结尾,应该是“发布JUnit测试结果报告”的选项。

我对JUnit本身并不太熟悉,但我猜它会生成(或有能力生成)并将结果放入xml文件中。您只需要在文本框中将路径放到xml文件中(相对于工作空间)。

完成此操作并创建构建后,您将在项目页面上获得详细的报告。然后,您应该可以单击每个测试的结果。

alt text