TEST
. This inner
class will be able to access anything in the package, including private data
within the outer class; but the outer class has no knowledge of it. If you
provide a main
method for the inner testing class, then it can
be executed to perform unit testing; but before deployment, the testing
classfiles are simply deleted and never appear in the deployed application.
This strategy is implemented in this module by means of a special compiler type and a special executor which cooperate to support inner test classes.
Information, bug reports, comments, and requests: please see
The module installs a new category of compiler type called Inner Tester Compiler.
Refer to the User's Guide for configuring and using custom compiler types in
general. This one has three special properties:
Note: normally you will not have any reason to mount the testing directory in
Filesystems. However, if some of your test code refers to test code in other classes,
in a complex system, you may need to mount it just so that the compiler can find
the cross-references. This is because other inner test classfiles are not available
by default in the main compiler's classpath, unless this directory is in
Filesystems. If you mount it, you will probably want to mark it hidden using
the customizer or using Filesystems Settings.
The special executor does two things differently from normal external execution:
Remember that you must configure the Main Compiler for the compiler
type before trying to compile objects created from this template!
innertesters.netbeans.org
.
Compilation
The special trick for compiling these classes is that first a regular Java compiler
is run as usual; it generated all classfiles, including the one for the inner
testing class. But then the inner testing classfile is removed from the source
directory and placed into a special scratch directory (temporary file area),
which need not be mounted in Filesystems.
When the main compiler is correctly configured and this special compiler is associated
with a source, the inner test classfile will automatically be moved to the designated
directory during compilation and building, and removed from it during cleaning.
TEST
): name of the inner
class to assume is implementing the testing.
c:\temp\innertst
): a scratch
directory where inner test classfiles may be kept.
Execution
You should again refer to the User's Guide for details on how to configure
custom executors in general. In the case of the Inner Tester Executor,
there are just two properties in addition to those usually used by external execution:
Inner Class Name and Test Directory. These should
be configured to be the same as for the compiler, above.
main
method from the testing class, rather than the
outer class, when you hit
Execute on the source file.
Template
The module also includes one template, in the Classes folder, called
Unit-testable Class. This is simply a demo of how to use the
module. It includes an inner testing class which tests some private functionality
of the outer class. Objects created from the template will have the correct
compiler and executor preset on them; you can create your own such templates
in a similar fashion if you prefer.