FeaturesPluginsDocs & SupportCommunityPartners

XTest Frequently Asked Questions

Last modification: January 22, 2007

Content

  1. Why do I get ClassNotFoundException when I run tests in IDE?
  2. Should I have to add SPL to test sources 
  3. I don't like the complexity of all the scripts and configuration files, is there any tool which can help me with it?
  4. My test contains several support classes, which are used inside the regular test classes. Where do I place them?
  5. Where I can store data or resources required by tests?
  6. When getting path to resources mounted in IDE's filesystem repository, it returns weird String instead of the standard path to the file.
  7. In my tests I need to use *.java files, but I don't want them to be compiled.
  8. What does mean values for 'xtest.source.location' property in test's build.xml file?
  9. Can I specify test which I would like to run from command line?
  10. Is it possible to pass some system properties to tests?
  11. My tests cannot find methods from NbTestCase, although I have the recent version of nbjunit.jar mounted in the filesystems.
  12. How do I find out what version of XTest I'm using? 
  13. The jar with tests (tests.jar) contains only .class, .jar, .xml, .ser and .properties files and all files in data folders. I would like to include files with other extensions.
  14. Why TransformXML task fails with "Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found"?
  15. I would like to include other files than the ones matching to patterns listed in ${xtest.home}/ standard-test-includes.txt. How should I do it?

Q: Why do I get ClassNotFoundException when I run tests in IDE?

A: It can happen you get ClassNotFoundException when you run tests inside NetBeans IDE. The exception says it cannot find a class from your module. To solve it make sure your test is not in the same package as missing class. If it is true, use for your tests some different package name which cannot clash with existing one (e.g. org.myorg.module.test or test.uitest). The problem is that tests are loaded by the system classloader and modules by the module classloader. And IDE cannot load classes in the same package using two different classloaders.

Q: Should I have to add SPL to test sources?

A: Yes, you should, test sources are integral part of netbeans source repository and thus they have to contain SPL as well as any other file inside the repository. Do not forget to place SPL to build.xml files as well.

Q: I don't like the complexity of all the scripts and configuration files, is there any tool which can help me with it?

A: Yes, you can use TestTools module, which should help you with the XTest setup, configuration and even test development (targeted mostly at functional GUI tests). The module can be downloaded from NetBeans's update center via your installation of NetBeans IDE (Tools/Update Center). You can also look at the TestTools homepage , where you can read about it more.

Q: My test contains several support classes, which are used inside the regular test classes. Where do I place them?

A: Create the hidden sub-package of the package where your test class lives.
If the support class has to be in the same package as your test class append the Hidden to the class name. Then you should add folowing lines to your build script, which will remove hidden classes from the junit batch test (extend the batchtest element of junit tasks).
    <exclude name="**/hidden/**"/>
    <exclude name="**/*Hidden.*"/>

Q: Where I can store data or resources required by tests?

A:  You should create package named 'data' and store your data files under it. Only for files placed in package named 'data' is guaranteed availibility for tests. For example you have test in package mymodule.myfeature, you just need to create package data (mymodule.myfeature.data) and place your files here. In your test you can use the following code when you need to access file named 'myresource.xml' (please note, the NbTestCase.convertNBFSURL() method is required when running the tests inside IDE and they are mounted in the file repository (as usually are). For more information, please see the next question):.
    String pathToDataDir =  NbTestCase.convertNBFSURL(this.getClass().getResource("data"));
    File myResource = new File(pathToDataDir,'myresource.xml');

Q: When getting path to resources mounted in IDE's filesystem repository, it returns weird String instead of the standard path to the file.

A:  Becasue IDE uses a special protocol when accessing files mounted in the filesystem repository, you need to convert the URL to the standard path by NbTestCase.convertNBFSURL() method (see example in the previous question). Please note, this method guarantees the correct path is returned only for resources mounted as local directories in the IDE's filesystem repository, not for jar/zip archives, CVS repositories, etc ....


Q: In my tests I need to use *.java files, but I don't want them to be compiled.

A:  You can create your own compiler and include only files you need to compile. You can also use the standard compiler (available in module_harness.xml file)  and before compiling you need to set 'compile.excludes' property to include all your files you don't want to compile. This property is passed to Ant's 'javac' task as  values for attribute 'excludes'. For more details please see 'javac' task in Ant and 'compile-one-dir' target in the module_harness.xml file.
    Example: <property name="compile.excludes" value="**/data/**"/> - no files will be compiled in data directories

Q: What does mean values for 'xtest.source.location' property in test's build.xml file?

A:  This property says against which code the tests will be run. This property can be set to the following values:
    • src - tests are run against compiled sources of the tested code (usually in ${module}/src directory)
    • jar - tests are run against built module/jar of the tested code (usually in ${module}/netbeans/${module}.jar
    • ide - tests are run against IDE


Q: Can I specify test which I would like to run from command line?

A:  Yes, you can use the following properties:
    • xtest.includes - to include tests to the selected testbag(s), for example 'ant -Dxtest.includes=HelloWorldTest.class/testGreeting1' would include test method testGreeting1 from class HelloWorldTest.
    • xtest.excludes - to exclude tests from the selected testbag(s)
Please note, xtest.includes and xtest.excludes only adds or remove additional tests to the current testbag. If you want to run only one tests specified via command line, you need to create a special testbag, which will contain no tests by default and use this testbag when running the desired tests.

Q: Is it possible to pass some system properties to tests?

A:  Yes, it's possible. All properties starting with "xtest.userdata|" or "xtest.userdata(<attrib>)|", where <attrib> is one of attributes used for test execution, are passed to tests. The prefix is removed before passing.

   Examples:

  • add such property into command line:
      ant runtests -Dxtest.userdata|my.system.property=myvalue
  • or add global property into build.xml which will be used only for tests with attribute "sys":
      <property name="xtest.userdata(sys)|my.system.property" value="myvalue">

    and execute tests with this attribute:
      ant runtests -Dxtest.attribs=stable,sys


Q: My tests cannot find methods from NbTestCase, although I have mounted the recent version of nbjunit.jar in the filesystems.

A:  You have probably installed JUnit module. This module contains a slightly older version of nbjunit.jar, which is stored in the lib/ext directory. You need to upgrade the JUnit module or to either remove nbjunit.jar file from lib/ext directory or replace it with the newer version available with XTest.

Q: How do I find out what version of XTest I'm using?

A:  Switch to your ${xtest.home} directory and call 'ant version'. This should give you the version number of XTest.


Q: The jar with tests (tests.jar) contains only .class, .jar, .xml, .ser and .properties files and all files in data folders. I would like to include files with other extensions.

A:  When building tests (more exactly in your compiler target) you can use jartests.includes and jartests.excludes properties to specify additional patterns (besides ${xtest.home}/standard-test-includes.txt and ${xtest.home}/standard-test-excludes.txtx} to be used when packing the jar with tests. The format of these properties is the same as includes/excludes attributes in jar ant task. So for example to include all java sources in the tests.jar you need to specify jartests.includes=**/src/*.java


Q: Why TransformXML task fails with "Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found"?

A:  You are probably using ant 1.5.x for release35 tests. Make sure you are using ant 1.4(.1) for release35 - this version is the only one officially supported for release35.


Q: 14. I would like to include other files than the ones matching to patterns listed in ${xtest.home}/ standard-test-includes.txt. How should I do it?

A: If you cannot (or don't want to) place these files to 'data' subpackage of your tests, you need to can supply property 'jartests.includes' to your compiler, which contains a patternset, which files you would like to include in the test distribution have to match. Please note, the patternset is relative to 'src' node of your tests. For example I would like include '.gif' files in my test distribution, so they can be used by tests - here's example of a simple compiler dealing with this:

<target name="unit-compiler" depends="set_classpath">
    <ant dir="." antfile="${xtest.module_harness.antfile}"
             target="buildtests">        
        <!-- src dir of my tests -->
        <property name="compile.srcdir" value="unit/src"/>
        <!-- extra includes to test distribution -->
        <property name="jartests.includes" value="**/*.gif"/>
    </ant>
</target>















Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Open ESB - The Open Enterprise Service Bus Powered by