testng-team / testng-eclipse

Eclipse plug-in for TestNG
https://testng.org
194 stars 164 forks source link

TestNG view should display the array content with a test accepting an array parameter via a dataProvider. #76

Closed JnRouvignac closed 11 years ago

JnRouvignac commented 11 years ago

I did not know where to report this bug: in testng-eclipse or testng. I decided to report it in testn-eclipse because this is where I see the outcome of this bug. Apologies if this was not the right place and feel free to move it to testng.

Consider the following test class:

package org.testng.sample;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataProviderReturnsArrayTestCase
{

  @DataProvider(name = "arrayInTheData")
  public Object[][] getArrayInTheData()
  {
    return new Object[][] { { new String[] { "a", "b", "c" } },
      { new String[] { "1", "2", "3" } } };
  }

  @Test(dataProvider = "arrayInTheData")
  public void testThatAcceptsAnArray(String[] strArray)
  {
    // test something...
  }
}

 

Here is the result of running this test in the TestNG view (it displays the result of calling toString() on an array): snapshot

 

I think this could be fixed by applying the following patch to testng:

diff --git a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java b/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
index 36397e6..6c9c323 100755
--- a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
+++ b/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
@@ -309,6 +309,20 @@ public class TestResultMessage implements IStringMessage {
       if(null == o) {
         result.add("null");
       }
+      else if (o.getClass().isArray()) {
+        String[] strArray = toString((Object[]) o, null);
+        StringBuilder sb = new StringBuilder("[");
+        for (int i = 0; i < strArray.length; i++)
+        {
+          sb.append(strArray[i]);
+          if (i + 1 < strArray.length)
+          {
+            sb.append(",");
+          }
+        }
+        sb.append("]");
+        result.add(sb.toString());
+      }
       else {
         String tostring= o.toString();
         if(isStringEmpty(tostring)) {

You may freely reuse the test class and the patch file I published in this issue under the terms of the Apache License Version 2.0.

JnRouvignac commented 11 years ago

Thank you very much!

frankbp commented 11 years ago

It's nice feature! Checking with latest TestNG 6.8.7 the array content will be displayed in report but the console remains the same, how about also change the console output to the same display as report did?