IDEA-142739 GeneralIdBasedToSMTRunnerEventsConvertor doesn't accept duration attribut...
[idea/community.git] / platform / smRunner / src / com / intellij / execution / testframework / sm / runner / events / TestFailedEvent.java
index c9e57612536087c3fcce835683f6bf6937ab8db9..8710d8196a262664dbebf0a9fe4834a4b5f83e5a 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.execution.testframework.sm.runner.events;
 
+import com.intellij.openapi.util.text.StringUtil;
 import jetbrains.buildServer.messages.serviceMessages.TestFailed;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -27,6 +28,7 @@ public class TestFailedEvent extends TreeNodeEvent {
   private final String myComparisonFailureActualText;
   private final String myComparisonFailureExpectedText;
   private final String myFilePath;
+  private final long myDurationMillis;
 
   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError) {
     this(testFailed, testError, null);
@@ -40,6 +42,18 @@ public class TestFailedEvent extends TreeNodeEvent {
     myComparisonFailureActualText = testFailed.getActual();
     myComparisonFailureExpectedText = testFailed.getExpected();
     myFilePath = filePath;
+    myDurationMillis = parseDuration(testFailed.getAttributes().get("duration"));
+  }
+
+  private static long parseDuration(@Nullable String durationStr) {
+    if (!StringUtil.isEmpty(durationStr)) {
+      try {
+        return Long.parseLong(durationStr);
+      }
+      catch (NumberFormatException ignored) {
+      }
+    }
+    return -1;
   }
 
   public TestFailedEvent(@NotNull String testName,
@@ -48,13 +62,34 @@ public class TestFailedEvent extends TreeNodeEvent {
                          boolean testError,
                          @Nullable String comparisonFailureActualText,
                          @Nullable String comparisonFailureExpectedText) {
-    super(testName, -1);
+    this(testName,
+         -1,
+         localizedFailureMessage,
+         stackTrace,
+         testError,
+         comparisonFailureActualText,
+         comparisonFailureExpectedText,
+         null,
+         -1);
+  }
+
+  public TestFailedEvent(@Nullable String testName,
+                         int id,
+                         @NotNull String localizedFailureMessage,
+                         @Nullable String stackTrace,
+                         boolean testError,
+                         @Nullable String comparisonFailureActualText,
+                         @Nullable String comparisonFailureExpectedText,
+                         @Nullable String expectedTextFilePath,
+                         long durationMillis) {
+    super(testName, id);
     myLocalizedFailureMessage = localizedFailureMessage;
     myStacktrace = stackTrace;
     myTestError = testError;
     myComparisonFailureActualText = comparisonFailureActualText;
     myComparisonFailureExpectedText = comparisonFailureExpectedText;
-    myFilePath = null;
+    myFilePath = expectedTextFilePath;
+    myDurationMillis = durationMillis;
   }
 
   @NotNull
@@ -93,4 +128,11 @@ public class TestFailedEvent extends TreeNodeEvent {
   public String getFilePath() {
     return myFilePath;
   }
+
+  /**
+   * @return the test duration in milliseconds, or -1 if undefined
+   */
+  public long getDurationMillis() {
+    return myDurationMillis;
+  }
 }