Browse Source

new attributes for the tests: hostname and timestamp.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276308 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 21 years ago
parent
commit
267fb740f2
2 changed files with 32 additions and 0 deletions
  1. +9
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.java
  2. +23
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

+ 9
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.java View File

@@ -86,4 +86,13 @@ public interface XMLConstants {
/** classname attribute for testcase elements */
String ATTR_CLASSNAME = "classname";

/**
* timestamp of test cases
*/
String TIMESTAMP = "timestamp";

/**
* name of host running the tests
*/
String HOSTNAME = "hostname";
}

+ 23
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java View File

@@ -25,12 +25,16 @@ import java.io.Writer;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Date;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.DOMElementWriter;
import org.apache.tools.ant.util.DateUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
@@ -100,6 +104,13 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
rootElement = doc.createElement(TESTSUITE);
rootElement.setAttribute(ATTR_NAME, suite.getName());

//add the timestamp
final String timestamp = DateUtils.format(new Date(),
DateUtils.ISO8601_DATETIME_PATTERN);
rootElement.setAttribute(TIMESTAMP,timestamp);
//and the hostname.
rootElement.setAttribute(HOSTNAME,getHostname());

// Output properties
Element propsElement = doc.createElement(PROPERTIES);
rootElement.appendChild(propsElement);
@@ -116,6 +127,18 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
}
}

/**
* get the local hostname
* @return the name of the local host, or "localhost" if we cannot work it out
*/
private String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
return "localhost";
}
}

/**
* The whole testsuite ended.
*/


Loading…
Cancel
Save