TestNG: NPE on groups configuration only

I am just getting started using TestNG (IntelliJ IDEA 8.1.3, TestNG 5.8, JDK 1.5, Mac OS X 10.6), and I have a strange situation in which my test case is run correctly when I execute an 'all' configuration or a 'suite' configuration, but when I try to invoke the test via a 'groups' configuration, then the test dies with a null pointer exception on the first line of the program.

My test case looks like this:
...

public class TestCase1 extends SeleneseTestNgHelper {
    @Test(groups = { "selenium"})
    public void testTestCase1() throws Exception {
        selenium.open("/Search");  // NPE exception occurs here
        ...



Note that if I intentionally misspell the group name in the test source ("Xselenium" instead of "selenium", e.g.), then I get a different and correct result: all tests succeed trivially, because none are run.

If I edit the TestNG XML file that IDEA generates for the groups configuration (below) and invoke it via a suite configuration, the test case fails with an NPE as before, unless I remove the <groups> tag for test purposes.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Custom suite" parallel="none">
  <parameter name="selenium.url" value="http://localhost:8080/">
  </parameter>
  <parameter name="selenium.browser" value="*firefox">
  </parameter>
  <parameter name="verbose" value="10">
  </parameter>
  <test verbose="1" name="cnv" annotations="JDK">
    <groups>
      <run>
        <include name="selenium"/>
      </run>
    </groups>
    <classes>
      <class name="test.TestCase1"/>
    </classes>
  </test>
</suite>


I'm at a loss as to how to proceed.

Thanks for any pointers!

-Kevin Murphy
4 comments
Comment actions Permalink

Might help if you posted the stacktrace with the NPE in it.

If you run TestNG from the command line/ant/maven using the suite.xml file generated by the IDEA plugin, does TestNG still crash?   (i.e. is it a problem in TestNG, or the TestNG plugin).  You could try replacing the version of testng shipped with the plugin with a newer version and see if that also helps..

Mark

0
Comment actions Permalink

If you run TestNG from the command line/ant/maven using the suite.xml file generated by the IDEA plugin, does TestNG still crash?   (i.e. is it a problem in TestNG, or the TestNG plugin).  You could try replacing the version of testng shipped with the plugin with a newer version and see if that also helps..



Mark,

Thanks for prodding me into digging further.  I discovered that the problem exists independent of the IDEA plugin; it occurs with vanilla TestNG 5.8 and 5.10 (not sure what version the plugin includes).  I guess this means that I should be posting this elsewhere.

The stack trace:


java.lang.NullPointerException
        at edu.chop.bic.TestCase1.testTestCase1(TestCase1.java:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:607)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
        at org.testng.TestRunner.runWorkers(TestRunner.java:759)
        at org.testng.TestRunner.privateRun(TestRunner.java:592)
        at org.testng.TestRunner.run(TestRunner.java:486)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
        at org.testng.SuiteRunner.run(SuiteRunner.java:204)
        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:867)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:832)
        at org.testng.TestNG.run(TestNG.java:748)
        at org.testng.TestNG.privateMain(TestNG.java:904)
        at org.testng.TestNG.main(TestNG.java:877)


For a while I wondered if this problem was related to my recent upgrade to Mac OS X 10.6 (Snow Leopard) (I started using TestNG after my upgrade, btw), which removed Java 5 and repointed Java 5 symlinks to Java 6.  I have since reinstalled the actual Java 5 and recompiled the project, but it fails in the same way every time.  Very peculiar.

I'm going to try this on a different platform.

0
Comment actions Permalink

I see from the stack trace the NPE looks to be occurring in your own test class itself?  What is the test doing?  Are you maybe assuming some fields being instantiated?

Its interesting you mention the move to 1.6 as well, there -was- a problem a while ago in TestNG which was revealed with JDK 6 to do with the ordering of which tests/methods were ran (internal changes in the JDK to with the natural order of entries in Sets tripped up a few projects) but I thought that was fixed around the 5.8/5.9 releases.

0
Comment actions Permalink

I'm answering this myself. Yes, this problem has absolutely nothing to do with IntelliJ. For posterity's sake, the problem stemmed from various misunderstandings on my part, partly due to embryonic Selenium documentation.  The way the SeleneseTestNgHelper class (my test case superclass in the Selenium framework I'm using) is written, it's impossible to use TestNG groups configuration unless you override the SeleneseTestNgHelper.setUp method and annotate it properly.  There doesn't seem to be any documentation on SeleneseTestNgHelper, and because I was unfamiliar with TestNG, I didn't realize that unless a setUp method is set to 'alwaysRun' or have a groups annotation, it's not going to be run when you run a group test.  Cédric Beust, TestNG's creator, was very responsive and helpful on the TestNG list.

0

Please sign in to leave a comment.