From 96e6561e659a24f1e2122d884e83561327cb0f48 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 28 Mar 2003 12:20:51 +0000 Subject: [PATCH] The xml formatter for JUnit will now honor test case names set with setName PR: 17040 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274340 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../junit/XMLJUnitResultFormatter.java | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 65ebceb6e..bebb5a09a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -195,6 +195,9 @@ Other changes: * Copy has a new outputencoding attribute that can be used to change the encoding while copying files. Bugzilla Report 18217. +* The xml formatter for JUnit will now honor test case names set with + setName. Bugzilla Report 17040. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java index 4e06f364f..23e14af08 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -103,6 +103,10 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan * Element for the current test. */ private Hashtable testElements = new Hashtable(); + /** + * tests that failed. + */ + private Hashtable failedTests = new Hashtable(); /** * Timing helper. */ @@ -186,12 +190,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan */ public void startTest(Test t) { testStarts.put(t, new Long(System.currentTimeMillis())); - - Element currentTest = doc.createElement(TESTCASE); - currentTest.setAttribute(ATTR_NAME, - JUnitVersionHelper.getTestCaseName(t)); - rootElement.appendChild(currentTest); - testElements.put(t, currentTest); } /** @@ -200,16 +198,24 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan *

A Test is finished. */ public void endTest(Test test) { - Element currentTest = (Element) testElements.get(test); - // Fix for bug #5637 - if a junit.extensions.TestSetup is // used and throws an exception during setUp then startTest // would never have been called - if (currentTest == null) { + if (!testStarts.containsKey(test)) { startTest(test); + } + + Element currentTest = null; + if (!failedTests.containsKey(test)) { + currentTest = doc.createElement(TESTCASE); + currentTest.setAttribute(ATTR_NAME, + JUnitVersionHelper.getTestCaseName(test)); + rootElement.appendChild(currentTest); + testElements.put(test, currentTest); + } else { currentTest = (Element) testElements.get(test); } - + Long l = (Long) testStarts.get(test); currentTest.setAttribute(ATTR_TIME, "" + ((System.currentTimeMillis() - l.longValue()) / 1000.0)); @@ -245,6 +251,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan private void formatError(String type, Test test, Throwable t) { if (test != null) { endTest(test); + failedTests.put(test, test); } Element nested = doc.createElement(type);