| org.netbeans.junit.NbTestCase
All known Subclasses: org.netbeans.junit.StdOutTest, org.netbeans.junit.AssertInstancesTest, org.netbeans.junit.diff.LineDiffTest, org.netbeans.junit.LinearSpeedTest, org.netbeans.junit.FlowControlTest, org.netbeans.junit.LoggingTest, org.netbeans.junit.NbPerformanceTestCase, org.netbeans.junit.NbTestCaseTest, org.netbeans.junit.RunInEventQueueTest, org.netbeans.junit.TimeOutTest, org.netbeans.junit.LoggingExceptionTest, org.netbeans.junit.MultiTestCase, org.netbeans.junit.NbTestCasePreferencesTest, org.netbeans.junit.ide.ProjectSupportTest, org.netbeans.junit.FlowCountingTest, org.netbeans.junit.TimeOutHasToPrintLogTest,
NbTestCase | abstract public class NbTestCase extends TestCase implements NbTest(Code) | | NetBeans extension to JUnit's
TestCase .
Adds various abilities such as comparing golden files, getting a working
directory for test files, testing memory usage, etc.
|
Constructor Summary | |
public | NbTestCase(String name) Constructs a test case with the given name. |
Method Summary | |
public static void | assertFile(String message, String test, String pass, String diff, Diff externalDiff) Asserts that two files are the same (their content is identical), when files
differ
org.netbeans.junit.AssertionFileFailedError AssertionFileFailedError exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which definesthe correct content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(String test, String pass, String diff, Diff externalDiff) Asserts that two files are the same, it uses specific
org.netbeans.junit.diff.Diff Diff implementation to
compare two files and stores possible differencies in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(String message, String test, String pass, String diff) Asserts that two files are the same, it compares two files and stores possible differencies
in the output file, the message is displayed when assertion fails.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(String test, String pass, String diff) Asserts that two files are the same, it compares two files and stores possible differencies
in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(String test, String pass) Asserts that two files are the same, it just compares two files and doesn't produce any additional output. | public static void | assertFile(String message, File test, File pass, File diff, Diff externalDiff) Asserts that two files are the same (their content is identical), when files
differ
org.netbeans.junit.AssertionFileFailedError AssertionFileFailedError exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which definesthe correct content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(File test, File pass, File diff, Diff externalDiff) Asserts that two files are the same, it uses specific
org.netbeans.junit.diff.Diff Diff implementation to
compare two files and stores possible differencies in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(String message, File test, File pass, File diff) Asserts that two files are the same, it compares two files and stores possible differencies
in the output file, the message is displayed when assertion fails.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(File test, File pass, File diff) Asserts that two files are the same, it compares two files and stores possible differencies
in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. | public static void | assertFile(File test, File pass) Asserts that two files are the same, it just compares two files and doesn't produce any additional output. | public static void | assertGC(String text, Reference> ref) Asserts that the object can be garbage collected. | public static void | assertGC(String text, Reference> ref, Set> rootsHint) Asserts that the object can be garbage collected. | public static void | assertSize(String message, int limit, Object root) Assert size of some structure. | public static void | assertSize(String message, Collection> roots, int limit) Assert size of some structure. | public static void | assertSize(String message, Collection> roots, int limit, Object[] skip) Assert size of some structure. | public static int | assertSize(String message, Collection> roots, int limit, MemoryFilter skip) Assert size of some structure. | public boolean | canRun() Checks if a test isn't filtered out by the active filter. | public void | clearWorkDir() Deletes all files including subdirectories in test's working directory. | public void | compareReferenceFiles(String testFilename, String goldenFilename, String diffFilename) Compares golden file and reference log. | public void | compareReferenceFiles() Compares default golden file and default reference log. | public static String | convertNBFSURL(URL url) Converts NetBeans filesystem URL to absolute path. | static void | deleteSubFiles(File file) | public static void | failByBug(int bugID) Fails a test with known bug ID. | public static void | failByBug(int bugID, String message) Fails a test with known bug ID and with the given message. | public File | getDataDir() Returns pointer to directory with test data (golden files, sample files, ...). | final long | getExecutionTime() | public String | getExpectedFail() Returns expected fail message. | public File | getGoldenFile(String filename) Get the test method specific golden file from ${xtest.data}/goldenfiles/${classname}
directory. | public File | getGoldenFile() | public PrintStream | getLog(String logName) Returns named log stream. | public PrintStream | getLog() Return default log named as ${testmethod}.log. | public PrintStream | getRef() Get PrintStream to log inteded for reference files comparision. | final protected int | getTestNumber() Parses the test name to find out whether it encodes a number. | public File | getWorkDir() Returns unique working directory for a test (each test method has a unique dir).
If not available, method tries to create it. | public String | getWorkDirPath() Returns path to test method working directory as a String. | public void | log(String message) | public void | log(String log, String message) | protected Level | logLevel() Allows easy collecting of log messages send thru java.util.logging API.
Overwrite and return the log level to collect logs to logging file. | public void | ref(String message) Easy to use logging method for printing a message to a reference log. | public void | run(TestResult result) Runs the test case, while conditionally skip some according to result of
NbTestCase.canRun method. | public void | runBare() Runs the bare test sequence. | protected boolean | runInEQ() Provide ability for tests, setUp and tearDown to request that they run only in the AWT event queue. | public void | setFilter(Filter filter) Sets active filter. | protected int | timeOut() Provides support for tests that can have problems with terminating. |
NbTestCase | public NbTestCase(String name)(Code) | | Constructs a test case with the given name.
Parameters: name - name of the testcase |
assertFile | public static void assertFile(String message, String test, String pass, String diff, Diff externalDiff)(Code) | | Asserts that two files are the same (their content is identical), when files
differ
org.netbeans.junit.AssertionFileFailedError AssertionFileFailedError exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which definesthe correct content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. Parameters: externalDiff - instance of class implementing the org.netbeans.junit.diff.Diff interface, it has to bealready initialized, when passed in this assertFile function. |
assertFile | public static void assertFile(String test, String pass, String diff, Diff externalDiff)(Code) | | Asserts that two files are the same, it uses specific
org.netbeans.junit.diff.Diff Diff implementation to
compare two files and stores possible differencies in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. Parameters: externalDiff - instance of class implementing the org.netbeans.junit.diff.Diff interface, it has to bealready initialized, when passed in this assertFile function. |
assertFile | public static void assertFile(String message, String test, String pass, String diff)(Code) | | Asserts that two files are the same, it compares two files and stores possible differencies
in the output file, the message is displayed when assertion fails.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. |
assertFile | public static void assertFile(String test, String pass, String diff)(Code) | | Asserts that two files are the same, it compares two files and stores possible differencies
in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. |
assertFile | public static void assertFile(String test, String pass)(Code) | | Asserts that two files are the same, it just compares two files and doesn't produce any additional output.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. |
assertFile | public static void assertFile(String message, File test, File pass, File diff, Diff externalDiff)(Code) | | Asserts that two files are the same (their content is identical), when files
differ
org.netbeans.junit.AssertionFileFailedError AssertionFileFailedError exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which definesthe correct content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. Parameters: externalDiff - instance of class implementing the org.netbeans.junit.diff.Diff interface, it has to bealready initialized, when passed in this assertFile function. |
assertFile | public static void assertFile(File test, File pass, File diff, Diff externalDiff)(Code) | | Asserts that two files are the same, it uses specific
org.netbeans.junit.diff.Diff Diff implementation to
compare two files and stores possible differencies in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. Parameters: externalDiff - instance of class implementing the org.netbeans.junit.diff.Diff interface, it has to bealready initialized, when passed in this assertFile function. |
assertFile | public static void assertFile(String message, File test, File pass, File diff)(Code) | | Asserts that two files are the same, it compares two files and stores possible differencies
in the output file, the message is displayed when assertion fails.
Parameters: message - the detail message for this assertion Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. |
assertFile | public static void assertFile(File test, File pass, File diff)(Code) | | Asserts that two files are the same, it compares two files and stores possible differencies
in the output file.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. Parameters: diff - file, where differences will be stored, when null differences will not be stored. In caseit points to directory the result file name is constructed from the pass argument and placed to thatdirectory. Constructed file name consists from the name of pass file (without extension and path) appendedby the '.diff'. |
assertFile | public static void assertFile(File test, File pass)(Code) | | Asserts that two files are the same, it just compares two files and doesn't produce any additional output.
Parameters: test - first file to be compared, by the convention this should be the test-generated file Parameters: pass - second file to be comapred, it should be so called 'golden' file, which defines thecorrect content for the test-generated file. |
assertGC | public static void assertGC(String text, Reference> ref)(Code) | | Asserts that the object can be garbage collected. Tries to GC ref's referent.
Parameters: text - the text to show when test fails. Parameters: ref - the referent to object thatshould be GCed |
assertGC | public static void assertGC(String text, Reference> ref, Set> rootsHint)(Code) | | Asserts that the object can be garbage collected. Tries to GC ref's referent.
Parameters: text - the text to show when test fails. Parameters: ref - the referent to object that should be GCed Parameters: rootsHint - a set of objects that should be considered part of therootset for this scan. This is useful if you want to verify that one structure(usually long living in real application) is not holding another structurein memory, without setting a static reference to the former structure.Example:// test bodyWeakHashMap map = new WeakHashMap();Object target = new Object();map.put(target, "Val");// verification stepReference ref = new WeakReference(target);target = null;assertGC("WeakMap does not hold the key", ref, Collections.singleton(map)); |
assertSize | public static void assertSize(String message, int limit, Object root)(Code) | | Assert size of some structure. Traverses the whole reference
graph of objects accessible from given root object and check its size
against the limit.
Parameters: message - the text to show when test fails. Parameters: limit - maximal allowed heap size of the structure Parameters: root - the root object from which to traverse |
assertSize | public static void assertSize(String message, Collection> roots, int limit)(Code) | | Assert size of some structure. Traverses the whole reference
graph of objects accessible from given roots and check its size
against the limit.
Parameters: message - the text to show when test fails. Parameters: roots - the collection of root objects from which to traverse Parameters: limit - maximal allowed heap size of the structure |
assertSize | public static void assertSize(String message, Collection> roots, int limit, Object[] skip)(Code) | | Assert size of some structure. Traverses the whole reference
graph of objects accessible from given roots and check its size
against the limit.
Parameters: message - the text to show when test fails. Parameters: roots - the collection of root objects from which to traverse Parameters: limit - maximal allowed heap size of the structure Parameters: skip - Array of objects used as a boundary during heap scanning,neither these objects nor references from these objectsare counted. |
assertSize | public static int assertSize(String message, Collection> roots, int limit, MemoryFilter skip)(Code) | | Assert size of some structure. Traverses the whole reference
graph of objects accessible from given roots and check its size
against the limit.
Parameters: message - the text to show when test fails. Parameters: roots - the collection of root objects from which to traverse Parameters: limit - maximal allowed heap size of the structure Parameters: skip - custom filter for counted objects actual size or -1 on internal error. |
canRun | public boolean canRun()(Code) | | Checks if a test isn't filtered out by the active filter.
true if the test can run |
clearWorkDir | public void clearWorkDir() throws IOException(Code) | | Deletes all files including subdirectories in test's working directory.
throws: IOException - if any problem has occured during deleting files/directories |
compareReferenceFiles | public void compareReferenceFiles(String testFilename, String goldenFilename, String diffFilename)(Code) | | Compares golden file and reference log. If both files are the
same, test passes. If files differ, test fails and diff file is
created (diff is created only when using native diff, for details
see JUnit module documentation)
Parameters: testFilename - reference log file name Parameters: goldenFilename - golden file name Parameters: diffFilename - diff file name (optional, if null, then no diff is created) |
compareReferenceFiles | public void compareReferenceFiles()(Code) | | Compares default golden file and default reference log. If both files are the
same, test passes. If files differ, test fails and default diff (${methodname}.diff)
file is created (diff is created only when using native diff, for details
see JUnit module documentation)
|
convertNBFSURL | public static String convertNBFSURL(URL url)(Code) | | Converts NetBeans filesystem URL to absolute path.
Parameters: url - URL to convert absolute path |
failByBug | public static void failByBug(int bugID)(Code) | | Fails a test with known bug ID.
Parameters: bugID - the bug number according bug report system. |
failByBug | public static void failByBug(int bugID, String message)(Code) | | Fails a test with known bug ID and with the given message.
Parameters: bugID - the bug number according bug report system. Parameters: message - the text to show when test fails. |
getDataDir | public File getDataDir()(Code) | | Returns pointer to directory with test data (golden files, sample files, ...).
It is the same from xtest.data property.
data directory |
getExecutionTime | final long getExecutionTime()(Code) | | in nanoseconds
|
getExpectedFail | public String getExpectedFail()(Code) | | Returns expected fail message.
expected fail message if it's expected this test fail, null otherwise. |
getGoldenFile | public File getGoldenFile(String filename)(Code) | | Get the test method specific golden file from ${xtest.data}/goldenfiles/${classname}
directory. If not found, try also deprecated src/data/goldenfiles/${classname}
resource directory.
Parameters: filename - filename to get from golden files directory golden file |
getGoldenFile | public File getGoldenFile()(Code) | | Get the default testmethod specific golden file from
data/goldenfiles/${classname}/${testmethodname}.pass
filename to get from golden files resource directory |
getLog | public PrintStream getLog(String logName)(Code) | | Returns named log stream. If log cannot be created as a file in the
testmethod working directory, PrintStream created from System.out is used. Please
note, that tests shoudn't call log.close() method, unless they really don't want
to use this log anymore.
Parameters: logName - name of the log - file in the working directory Log PrintStream |
getLog | public PrintStream getLog()(Code) | | Return default log named as ${testmethod}.log. If the log cannot be created
as a file in testmethod working directory, PrinterStream to System.out is returned
log |
getRef | public PrintStream getRef()(Code) | | Get PrintStream to log inteded for reference files comparision. Reference
log is stored as a file named ${testmethod}.ref in test method working directory.
If the file cannot be created, the testcase will automatically fail.
PrintStream to referencing log |
getTestNumber | final protected int getTestNumber()(Code) | | Parses the test name to find out whether it encodes a number. The
testSomeName1343 represents nubmer 1343.
the number exception: may - throw AssertionFailedError if the number is not found in the test name |
getWorkDir | public File getWorkDir() throws IOException(Code) | | Returns unique working directory for a test (each test method has a unique dir).
If not available, method tries to create it. This method uses
NbTestCase.getWorkDirPath method to determine the unique path.
Warning: the working directory is not guaranteed
to be empty when you get it, so if this is being called in
NbTestCase.setUp you
are strongly advised to first call
NbTestCase.clearWorkDir to ensure that each
test run starts with a clean slate.
throws: IOException - if the directory cannot be created file to the working directory directory |
getWorkDirPath | public String getWorkDirPath()(Code) | | Returns path to test method working directory as a String. Path is constructed
as ${nbjunit.workdir}/${package}.${classname}/${testmethodname}. (The nbjunit.workdir
property should be set in junit.properties; otherwise the default is ${java.io.tmpdir}/tests.)
Please note that this method does not guarantee that the working directory really exists.
a path to a test method working directory |
log | public void log(String message)(Code) | | Simple and easy to use method for printing a message to a default log
Parameters: message - meesage to log |
log | public void log(String log, String message)(Code) | | Easy to use method for logging a message to a named log
Parameters: log - which log to use Parameters: message - message to log |
logLevel | protected Level logLevel()(Code) | | Allows easy collecting of log messages send thru java.util.logging API.
Overwrite and return the log level to collect logs to logging file.
If the method returns non-null level, then the level is assigned to
the Logger.getLogger("") and the messages reported to it
are then send into regular log file (which is accessible thru
NbTestCase.getLog )
and in case of failure the last few messages is also included
in failure.getMessage() .
default implementation returns null which disables any loggingsupport in test since: 1.27 See Also: Log.enable |
ref | public void ref(String message)(Code) | | Easy to use logging method for printing a message to a reference log.
Parameters: message - message to log |
run | public void run(TestResult result)(Code) | | Runs the test case, while conditionally skip some according to result of
NbTestCase.canRun method.
|
runBare | public void runBare() throws Throwable(Code) | | Runs the bare test sequence. It checks
NbTestCase.runInEQ and possibly
schedules the call of setUp , runTest and tearDown
to AWT event thread. It also consults
NbTestCase.timeOut and if so, it starts a
count down and aborts the runTest if the time out expires.
exception: Throwable - if any exception is thrown |
runInEQ | protected boolean runInEQ()(Code) | | Provide ability for tests, setUp and tearDown to request that they run only in the AWT event queue.
By default, false.
true to run all test methods, setUp and tearDown in the EQ, false to run in whatever thread |
setFilter | public void setFilter(Filter filter)(Code) | | Sets active filter.
Parameters: filter - Filter to be set as active for current test, null will reset filtering. |
timeOut | protected int timeOut()(Code) | | Provides support for tests that can have problems with terminating.
Runs the test in a "watchdog" that measures the time the test shall
take and if it does not terminate it reports a failure.
amount ms to give one test to finish or 0 (default) to disable time outs since: 1.20 |
|
|