|
org.netbeans.modules.nbjunit/1 1.41 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.netbeans.junit.NbTestCase
public abstract class NbTestCase
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 | |
---|---|
NbTestCase(String name)
Constructs a test case with the given name. |
Method Summary | |
---|---|
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. |
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. |
static void |
assertFile(File test,
File pass,
File diff,
Diff externalDiff)
Asserts that two files are the same, it uses specific Diff implementation to
compare two files and stores possible differencies in the output file. |
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. |
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 AssertionFileFailedError exception is thrown. |
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. |
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. |
static void |
assertFile(String test,
String pass,
String diff,
Diff externalDiff)
Asserts that two files are the same, it uses specific Diff implementation to
compare two files and stores possible differencies in the output file. |
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. |
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 AssertionFileFailedError exception is thrown. |
static void |
assertGC(String text,
Reference<?> ref)
Asserts that the object can be garbage collected. |
static void |
assertGC(String text,
Reference<?> ref,
Set<?> rootsHint)
Asserts that the object can be garbage collected. |
static void |
assertSize(String message,
Collection<?> roots,
int limit)
Assert size of some structure. |
static int |
assertSize(String message,
Collection<?> roots,
int limit,
MemoryFilter skip)
Assert size of some structure. |
static void |
assertSize(String message,
Collection<?> roots,
int limit,
Object[] skip)
Assert size of some structure. |
static void |
assertSize(String message,
int limit,
Object root)
Assert size of some structure. |
boolean |
canRun()
Checks if a test isn't filtered out by the active filter. |
void |
clearWorkDir()
Deletes all files including subdirectories in test's working directory. |
void |
compareReferenceFiles()
Compares default golden file and default reference log. |
void |
compareReferenceFiles(String testFilename,
String goldenFilename,
String diffFilename)
Compares golden file and reference log. |
static String |
convertNBFSURL(URL url)
Deprecated. No longer applicable as of NB 4.0 at the latest. FileObject.getURL() should be returning a file -protocol
URL, which can be converted to a disk path using new File(URI) ; or
use FileUtil.toFile . |
static void |
failByBug(int bugID)
Fails a test with known bug ID. |
static void |
failByBug(int bugID,
String message)
Fails a test with known bug ID and with the given message. |
File |
getDataDir()
Returns pointer to directory with test data (golden files, sample files, ...). |
String |
getExpectedFail()
Returns expected fail message. |
File |
getGoldenFile()
Get the default testmethod specific golden file from data/goldenfiles/${classname}/${testmethodname}.pass |
File |
getGoldenFile(String filename)
Get the test method specific golden file from ${xtest.data}/goldenfiles/${classname} directory. |
PrintStream |
getLog()
Return default log named as ${testmethod}.log. |
PrintStream |
getLog(String logName)
Returns named log stream. |
PrintStream |
getRef()
Get PrintStream to log inteded for reference files comparision. |
protected int |
getTestNumber()
Parses the test name to find out whether it encodes a number. |
File |
getWorkDir()
Returns unique working directory for a test (each test method has a unique dir). |
String |
getWorkDirPath()
Returns path to test method working directory as a String. |
void |
log(String message)
Simple and easy to use method for printing a message to a default log |
void |
log(String log,
String message)
Easy to use method for logging a message to a named log |
protected Level |
logLevel()
Allows easy collecting of log messages send thru java.util.logging API. |
void |
ref(String message)
Easy to use logging method for printing a message to a reference log. |
void |
run(junit.framework.TestResult result)
Runs the test case, while conditionally skip some according to result of canRun() method. |
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. |
void |
setFilter(Filter filter)
Sets active filter. |
protected int |
timeOut()
Provides support for tests that can have problems with terminating. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, runTest, setName, setUp, tearDown, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface junit.framework.Test |
---|
countTestCases |
Constructor Detail |
---|
public NbTestCase(String name)
name
- name of the testcaseMethod Detail |
---|
public void setFilter(Filter filter)
filter
- Filter to be set as active for current test, null will reset filtering.public String getExpectedFail()
getExpectedFail
in interface NbTest
public boolean canRun()
protected boolean runInEQ()
protected int timeOut()
protected Level logLevel()
Logger.getLogger("")
and the messages reported to it
are then send into regular log file (which is accessible thru getLog(java.lang.String)
)
and in case of failure the last few messages is also included
in failure.getMessage()
.
null
which disables any logging
support in testLog.enable(java.lang.String, java.util.logging.Level)
public void run(junit.framework.TestResult result)
canRun()
method.
run
in interface junit.framework.Test
run
in class junit.framework.TestCase
public void runBare() throws Throwable
runInEQ()
and possibly
schedules the call of setUp
, runTest
and tearDown
to AWT event thread. It also consults timeOut()
and if so, it starts a
count down and aborts the runTest
if the time out expires.
runBare
in class junit.framework.TestCase
Throwable
- if any exception is thrownprotected final int getTestNumber()
may
- throw AssertionFailedError if the number is not found in the test namepublic static void assertFile(String message, String test, String pass, String diff, Diff externalDiff)
AssertionFileFailedError
exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
message
- the detail message for this assertiontest
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines
the correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.externalDiff
- instance of class implementing the Diff
interface, it has to be
already initialized, when passed in this assertFile function.public static void assertFile(String test, String pass, String diff, Diff externalDiff)
Diff
implementation to
compare two files and stores possible differencies in the output file.
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.externalDiff
- instance of class implementing the Diff
interface, it has to be
already initialized, when passed in this assertFile function.public static void assertFile(String message, String test, String pass, String diff)
message
- the detail message for this assertiontest
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.public static void assertFile(String test, String pass, String diff)
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.public static void assertFile(String test, String pass)
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.public static void assertFile(String message, File test, File pass, File diff, Diff externalDiff)
AssertionFileFailedError
exception is thrown.
Depending on the Diff implementation additional output can be generated to the file/dir specified by the
diff param.
message
- the detail message for this assertiontest
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines
the correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.externalDiff
- instance of class implementing the Diff
interface, it has to be
already initialized, when passed in this assertFile function.public static void assertFile(File test, File pass, File diff, Diff externalDiff)
Diff
implementation to
compare two files and stores possible differencies in the output file.
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.externalDiff
- instance of class implementing the Diff
interface, it has to be
already initialized, when passed in this assertFile function.public static void assertFile(String message, File test, File pass, File diff)
message
- the detail message for this assertiontest
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.public static void assertFile(File test, File pass, File diff)
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.diff
- file, where differences will be stored, when null differences will not be stored. In case
it points to directory the result file name is constructed from the pass argument and placed to that
directory. Constructed file name consists from the name of pass file (without extension and path) appended
by the '.diff'.public static void assertFile(File test, File pass)
test
- first file to be compared, by the convention this should be the test-generated filepass
- second file to be comapred, it should be so called 'golden' file, which defines the
correct content for the test-generated file.public String getWorkDirPath()
public File getWorkDir() throws IOException
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 TestCase.setUp()
you
are strongly advised to first call clearWorkDir()
to ensure that each
test run starts with a clean slate.
IOException
- if the directory cannot be createdpublic void clearWorkDir() throws IOException
IOException
- if any problem has occured during deleting files/directoriespublic PrintStream getLog(String logName)
logName
- name of the log - file in the working directory
public PrintStream getLog()
public void log(String message)
message
- meesage to logpublic void log(String log, String message)
log
- which log to usemessage
- message to logpublic PrintStream getRef()
public void ref(String message)
message
- message to logpublic File getGoldenFile(String filename)
filename
- filename to get from golden files directory
public File getDataDir()
public File getGoldenFile()
public void compareReferenceFiles(String testFilename, String goldenFilename, String diffFilename)
testFilename
- reference log file namegoldenFilename
- golden file namediffFilename
- diff file name (optional, if null, then no diff is created)public void compareReferenceFiles()
public static String convertNBFSURL(URL url)
FileObject.getURL()
should be returning a file
-protocol
URL, which can be converted to a disk path using new File(URI)
; or
use FileUtil.toFile
.
url
- URL to convert
public static void assertGC(String text, Reference<?> ref)
text
- the text to show when test fails.ref
- the referent to object that
should be GCedpublic static void assertGC(String text, Reference<?> ref, Set<?> rootsHint)
text
- the text to show when test fails.ref
- the referent to object that should be GCedrootsHint
- a set of objects that should be considered part of the
rootset for this scan. This is useful if you want to verify that one structure
(usually long living in real application) is not holding another structure
in memory, without setting a static reference to the former structure.
// test body WeakHashMap map = new WeakHashMap(); Object target = new Object(); map.put(target, "Val"); // verification step Reference ref = new WeakReference(target); target = null; assertGC("WeakMap does not hold the key", ref, Collections.singleton(map));
public static void assertSize(String message, int limit, Object root)
message
- the text to show when test fails.limit
- maximal allowed heap size of the structureroot
- the root object from which to traversepublic static void assertSize(String message, Collection<?> roots, int limit)
message
- the text to show when test fails.roots
- the collection of root objects from which to traverselimit
- maximal allowed heap size of the structurepublic static void assertSize(String message, Collection<?> roots, int limit, Object[] skip)
message
- the text to show when test fails.roots
- the collection of root objects from which to traverselimit
- maximal allowed heap size of the structureskip
- Array of objects used as a boundary during heap scanning,
neither these objects nor references from these objects
are counted.public static int assertSize(String message, Collection<?> roots, int limit, MemoryFilter skip)
message
- the text to show when test fails.roots
- the collection of root objects from which to traverselimit
- maximal allowed heap size of the structureskip
- custom filter for counted objects
-1
on internal error.public static void failByBug(int bugID)
bugID
- the bug number according bug report system.public static void failByBug(int bugID, String message)
bugID
- the bug number according bug report system.message
- the text to show when test fails.
|
org.netbeans.modules.nbjunit/1 1.41 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |