Change firing of starttest event.
Original code assumed that a targetstart event
would always happen. However, this is not the case
if the target depends on a SetUp target that fails.
In this case the resultant xml result file was malformed.
This change always fires a starttest event, matching
the endtest event which is always send (from a finally block).


git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@568703 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/org/apache/ant/antunit/AntUnit.java b/src/main/org/apache/ant/antunit/AntUnit.java
index f5952d0..a560be1 100644
--- a/src/main/org/apache/ant/antunit/AntUnit.java
+++ b/src/main/org/apache/ant/antunit/AntUnit.java
@@ -243,6 +243,7 @@
                     v.add(name);
                     LogCapturer lc = new LogCapturer(newProject);
                     try {
+                        fireStartTest(name);
                         newProject.executeTargets(v);
                     } catch (AssertionFailedException e) {
                         fireFail(name, e);
@@ -406,6 +407,18 @@
     }
 
     /**
+     * invokes start on all registered test listeners.
+     * @param targetName the name of the target.
+     */
+    private void fireStartTest(String targetName) {
+        Iterator it = listeners.iterator();
+        while (it.hasNext()) {
+            AntUnitListener al = (AntUnitListener) it.next();
+            al.startTest(targetName);
+        }
+    }
+
+    /**
      * invokes addFailure on all registered test listeners.
      * @param targetName the name of the failed target.
      * @param ae the associated AssertionFailedException.
@@ -464,10 +477,6 @@
             a.endTestSuite(event.getProject(), buildFile);
         }
         public void targetStarted(BuildEvent event) {
-            String tName = event.getTarget().getName();
-            if (tName.startsWith(TEST)) {
-                a.startTest(tName);
-            }
         }
         public void targetFinished(BuildEvent event) {
         }