Test Reporting Issue

68 views
Skip to first unread message

hopen

unread,
Mar 10, 2010, 1:23:15 PM3/10/10
to testng-users
I have been using TestNG in Eclipse for a while. Just upgraded to
latest Eclipse with latest TestNG plug-in. My test suite runs fine.
But failed on generating reports with the following exception. Please
help

java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at java.util.Properties.setProperty(Properties.java:143)
at
org.testng.reporters.JUnitXMLReporter.createElement(JUnitXMLReporter.java:
157)
at
org.testng.reporters.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:
146)
at
org.testng.reporters.JUnitXMLReporter.onFinish(JUnitXMLReporter.java:
100)
at org.testng.TestRunner.fireEvent(TestRunner.java:1217)
at org.testng.TestRunner.afterRun(TestRunner.java:994)
at org.testng.TestRunner.run(TestRunner.java:523)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:323)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:318)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:290)
at org.testng.SuiteRunner.run(SuiteRunner.java:195)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:907)
at org.testng.TestNG.runSuitesLocally(TestNG.java:874)
at org.testng.TestNG.run(TestNG.java:783)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:127)

Cédric Beust ♔

unread,
Mar 10, 2010, 1:27:55 PM3/10/10
to testng...@googlegroups.com
Can you post your test class?

-- 
Cedric



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


hopen

unread,
Mar 10, 2010, 5:06:49 PM3/10/10
to testng-users
You gave me part of the answer by asking the question. While I was
constructing a simple test, I found out that the problem is somehow
related to using test class inheritance. In the following example, if
I remove the base class and pass the parameters to the test class
directly, everything is fine. Now this leads me to ask a more general
TestNG test design question.

I have a number of tests all share a set of common properties such as
"host" and "port" in the following example. Other than that they are
not related and there are a lot of them. So I would like to make
different tests classes. Ideally, I would like to load the common
parameters once @BeforeSuite. Then all the test classes can use it.
What is the best way to do this? I could not figure it out at the
time. Using test inheritance like in the following example worked for
me until now.

----------------- test classes -------------------------
public class TestTest extends TestBaseClass {
@Test
public void doTest() {
System.out.println("this does nothing!");
}
}

public class TestBaseClass implements ITest {
private String name;

public String getTestName() {
return name;
}

protected void setTestName(String name) {
this.name = name;
}

@BeforeClass
@Parameters( { "host", "port" })
public void openSocket(String host, int port) {
System.out.println("Host: " + host);
System.out.println("Port: " + port);
}
}
------------------ testng.xml ---------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Test">
<parameter name="host" value="localhost" />
<parameter name="port" value="6666" />
<test name="Test Test">
<classes>
<class name="TestTest" />
</classes>
</test>
</suite>

Cédric Beust ♔

unread,
Mar 10, 2010, 5:18:44 PM3/10/10
to testng...@googlegroups.com
You could switch to a data provider and use a class annotation to apply the data provider to all your test methods (this will work with a base class as well):

@Test(dataProvider = "dp")
public class A {

  private void log(String s) {
    System.out.println("[A]" + s);
  }

  @DataProvider
  public Object[][] dp() {
    return new Object[][] {
      new Object[] { 42 },   
    };
  }

  public void f1(Integer n) {
    log("f1 " + n);
  }

  public void f2(Integer n) {
    log("f2 " + n);
  }
}

[A]f1 42
[A]f2 42
PASSED: This is test A(42)
PASSED: This is test A(42)

-- 
Cedric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


hopen

unread,
Mar 11, 2010, 11:55:54 AM3/11/10
to testng-users
Cédric, Thanks a lot for the reply. I did consider using a data
provider (BTW, I have your book. It was great). The issue with that
is I need to make these parameters configurable by people who are not
JAVA developers. Then the data provider will need parameters. If I
put the data provider in base class, I am back to the same issue of
passing parameters to base class.

Cédric Beust ♔

unread,
Mar 11, 2010, 12:03:19 PM3/11/10
to testng...@googlegroups.com
I'm afraid it's the only way right now since @Parameters is not supported at the class level (no particular reason except that this annotation is not used as often as @DataProvider, so I just didn't bother adding support for this).

-- 
Cedric



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


hopen

unread,
Mar 11, 2010, 12:53:38 PM3/11/10
to testng-users
More discovery -- If the base class does not implements ITest,
everything is fine. It makes sense, since the name is only used for
reports. I don't need the test name. I will just resolve this by
taking it out.

Cédric Beust ♔

unread,
Mar 11, 2010, 12:59:45 PM3/11/10
to testng...@googlegroups.com
Indeed, your getName() method must have been returning null, which caused the error you mentioned in your first email.

-- 
Cedric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


Reply all
Reply to author
Forward
0 new messages