XTestReplacementCookBook

Background

FitnessTestsWithoutX

Some tips on converting tests

Creating NbTestSuite

First you need to do is to create an instance of NbModuleSuite where NbTestSuite was created before.

You can do it like this (check DocumentsDialogOperatorTest in Jellytools):

NbModuleSuite.create(NbModuleSuite.createConfiguration(<test class>).
  addTest(<test method>).addTest(<test method>)[...].enableModules(".*").clusters(".*")

or like this:

NbModuleSuite.create(NbModuleSuite.createConfiguration(<test class>).
  addTest(<test method>, <test method>[...]).enableModules(".*").clusters(".*")

or

NbModuleSuite.create(<test class>,".*",".*", <test method>, <test method>[...])

or, if all test methods could be executed in no particular order, like this:

NbModuleSuite.create(NbModuleSuite.createConfiguration(<test class>).
  enableModules(".*").clusters(".*")

or

NbModuleSuite.create(<test class>,".*",".*")

Or, if your test extends JellyTestCase, you can do it like this (check NewFileNameLocationStepOperatorTest in Jellytools):

createModuleTest(<test class>, <test method>, <test method>[...]);

or, again, for all tests, like this:

createModuleTest(<test class>);

Accessing test data.

Data files needed for test should be in qa-functional/data folder. You can, then, reach it by getDataDir() method of NbTestCase.

Loading projects

If your test extends JellyTestCase, you can use this shortcut:

JellyTestCase.openDataProjects(String ...)

Please remember use paths relative to the qa-functional/data folder.

The best place to do it, so far, is from setUp() method - I do not have a better story yet.

The loadProjects(String...) method also takes care about scan been completed, so test stability should not be affected.

Also, check JellyTestCase.closeOpenedProjects().

Loading projects on startup.

No answer to this, so far.

Lifecycle

Tests are now constructed before IDE is executed. That means that no resources have been initialized by the time the class is loaded or the suite method is called. You have to initialize them on your own somewhere during the execution: setUp() or test methods.

For example, if there are public static final variables whose values are gotten from resource files, you need to move the initialization somewhere else (check OptionsOperatorTest in Jellytools).

Passing properties to tests.

System properties could be passed to tests if you use the test-qa-functional-sys-prop. prefix.

These can be placed in project.properties if for everyone to use:

test-qa-functional-sys-prop.<property name>=<property value>

or in nbproject/private/private.properties if just for you.

You can also do it while executing the tests from command line:

ant test ... -Dtest-qa-functional-sys-prop.<property name>=<property value>

Executing tests with GlassFish

This is obsolete; check FitnessTestsWithoutX.

First, you need to modify the tests to add GF to the system. You can use JellyTestCase.getGlassFishV2Node() as a shortcut.

Next, you need to specify where the Glassfish is installed. If you use the shortcut method mentioned above, you should do it by setting com.sun.aas.installRoot system property, which you can set as above.

Test configs

Check FitnessTestsWithoutX. In addition to that:

If you have tests which require certain execution order (i.e. you have to list test methods in suite() method), then it make sense to list test methods in a static array within the test class like this:

static String[] TESTS = { 
  "testInvoke",
  "testVerify",
  "testSelectDocument",
  "testSelectDocuments",
  // ...
};

This way, you would be able to reuse them in the suite() method:

public static Test suite() {
  return NbModuleSuite.create(DocumentsDialogOperatorTest.class, ".*", ".*", TESTS);
}

And in the configuration class:

public class DialogsTests {
  public static Test suite() {
      return NbModuleSuite.create(NbModuleSuite.createConfiguration(WizardOperatorTest.class).
        addTest(DocumentsDialogOperatorTest.class, DocumentsDialogOperatorTest.TESTS).
        addTest(WizardOperatorTest.class).
        clusters(".*").enableModules(".*"));
  }
}


Troubleshooting

Some people experience OutOfMemoryError while executing their tests. By default, netbeans.org modules get

test.run.args=-ea -XX:PermSize=32m -XX:MaxPermSize=200m -Xmx256m

which should be enough to test the NetBeans IDE. If your tests suck up a lot of RAM (or you are running tests in an external module or module suite) then you can specify different JVM parameters according to your needs: just define a different test.run.args in project.properties.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo