|
CS 1705 Library | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
cs1705.TestCase
public class TestCase
This class provides some customized behavior beyond the basics of
TestCase to support testing of I/O driven
programs and flexible/fuzzy comparison of strings. In most cases, it
can be used as a completely transparent drop-in replacement for its
parent class. Subclasses that override tearDown() should also
override setUp()--be sure to call super.setUp() in this case,
or you'll see unexpected behavior!
Fuzzy string comparisons in this class default to standard rules in
StringNormalizer (excluding the OPT_* rules). You can use
the stringNormalizer() method to access the normalizer and
set your own comparison options, however.
| Constructor Summary | |
|---|---|
TestCase()
Creates a new TestCase object. |
|
TestCase(String name)
Creates a new TestCase object. |
|
| Method Summary | |
|---|---|
static void |
assertFalse(boolean condition)
Asserts that a condition is false. |
static void |
assertFalse(String message,
boolean condition)
Asserts that a condition is false. |
void |
assertFuzzyEquals(String expected,
String actual)
Asserts that two Strings are equal, respecting preferences for what differences matter. |
void |
assertFuzzyEquals(String message,
String expected,
String actual)
Asserts that two Strings are equal, respecting preferences for what differences matter. |
static void |
assertTrue(boolean condition)
Asserts that a condition is true. |
static void |
assertTrue(String message,
boolean condition)
Asserts that a condition is true. |
static String |
compact(String content)
Takes a string and, if it is too long, shortens it by replacing the middle with an ellipsis. |
static String |
compact(String content,
int threshold,
int prefixLen)
Takes a string and, if it is too long, shortens it by replacing the middle with an ellipsis. |
boolean |
contains(String largerString,
String substring)
Determine whether one String contains another as a substring. |
boolean |
contains(String largerString,
String[] substrings)
Determine whether one String contains a sequence of other substrings in order. |
boolean |
containsRegex(String largerString,
Pattern substring)
Determine whether one String contains another as a substring, where the expected substring is specified as a regular expression. |
boolean |
containsRegex(String largerString,
Pattern[] substrings)
Determine whether one String contains a sequence of other substrings in order, where the expected substrings are specified as a regular expressions. |
boolean |
containsRegex(String largerString,
String substring)
Determine whether one String contains another as a substring, where the expected substring is specified as a regular expression. |
boolean |
containsRegex(String largerString,
String[] substrings)
Determine whether one String contains a sequence of other substrings in order, where the expected substrings are specified as a regular expressions. |
boolean |
equals(String left,
String right)
Determines whether two Strings are equal. |
boolean |
equalsRegex(String actual,
Pattern expected)
Determines whether a String exactly matches an expected regular expression. |
boolean |
equalsRegex(String actual,
String expected)
Determines whether a String exactly matches an expected regular expression. |
boolean |
fuzzyContains(String largerString,
String substring)
Determine whether one String contains another as a substring, respecting preferences for what differences matter. |
boolean |
fuzzyContains(String largerString,
String[] substrings)
Determine whether one String contains a sequence of other substrings in order, respecting preferences for what differences matter. |
boolean |
fuzzyContainsRegex(String largerString,
Pattern substring)
Determine whether one String contains another as a substring, where the expected substring is specified as a regular expression, and respecting preferences for what differences matter. |
boolean |
fuzzyContainsRegex(String largerString,
Pattern[] substrings)
Determine whether one String contains a sequence of other substrings in order, where the expected substrings are specified as regular expressions, and respecting preferences for what differences matter. |
boolean |
fuzzyContainsRegex(String largerString,
String substring)
Determine whether one String contains another as a substring, where the expected substring is specified as a regular expression, and respecting preferences for what differences matter. |
boolean |
fuzzyContainsRegex(String largerString,
String[] substrings)
Determine whether one String contains a sequence of other substrings in order, where the expected substrings are specified as regular expressions, and respecting preferences for what differences matter. |
boolean |
fuzzyEquals(String left,
String right)
Determines whether two Strings are equal, respecting preferences for what differences matter. |
boolean |
fuzzyEqualsRegex(String actual,
Pattern expected)
Determines whether a String exactly matches an expected regular expression, respecting preferences for what differences matter. |
boolean |
fuzzyEqualsRegex(String actual,
String expected)
Determines whether a String exactly matches an expected regular expression, respecting preferences for what differences matter. |
Scanner |
in()
Get an input stream containing the contents that you specify. |
PrintWriterWithHistory |
out()
Get an output stream suitable for use in test cases. |
void |
setIn(Scanner contents)
Set the contents of this test case's input stream, which can then be retrieved using in(). |
void |
setIn(String contents)
Set the contents of this test case's input stream, which can then be retrieved using in(). |
void |
setSystemIn(String contents)
Set the contents of this test case's input stream, which can then be retrieved using in(). |
PrintStreamWithHistory |
systemErr()
Get a version of System.err that records its history
so you can compare against it later. |
PrintStreamWithHistory |
systemOut()
Get a version of System.out that records its history
so you can compare against it later. |
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, getName, run, run, runBare, setName, 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, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, fail, fail |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TestCase()
public TestCase(String name)
name - The name of this test case| Method Detail |
|---|
public PrintWriterWithHistory out()
PrintWriterWithHistory.getHistory() method to
extract all the output in the form of a string. The contents of this
stream get cleared for every test case.
PrintWriter suitable for use in test casespublic PrintStreamWithHistory systemOut()
System.out that records its history
so you can compare against it later. The history of this
stream gets cleared for every test case.
PrintStream connected to System.out that
is suitable for use in test casespublic PrintStreamWithHistory systemErr()
System.err that records its history
so you can compare against it later. The history of this
stream gets cleared for every test case.
PrintStream connected to System.err that
is suitable for use in test casespublic Scanner in()
setIn(String) or
setIn(Scanner) to set the contents before you begin
using this stream. This stream gets reset for every test case.
Scanner containing any contents you
have specified.public void setIn(String contents)
in().
contents - The contents to use for the stream, which replace
any that were there before.public void setIn(Scanner contents)
in().
contents - The contents to use for the stream, which replace
any that were there before.public void setSystemIn(String contents)
in().
contents - The contents to use for the stream, which replace
any that were there before.
public void assertFuzzyEquals(String expected,
String actual)
Assert.assertEquals(String,String)
method, augmenting its behavior with the ability to make "fuzzy"
string comparisons that ignore things like differences in spacing,
punctuation, or capitalization. Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
expected - The expected valueactual - The value to test
public void assertFuzzyEquals(String message,
String expected,
String actual)
Assert.assertEquals(String,String)
method, augmenting its behavior with the ability to make "fuzzy"
string comparisons that ignore things like differences in spacing,
punctuation, or capitalization. Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
message - The message to use for a failed assertionexpected - The expected valueactual - The value to test
public static void assertTrue(String message,
boolean condition)
Assert.assertTrue(String,boolean)
that issues special diagnostics when the assertion fails, if
the given condition supports it.
message - The message to use for a failed assertioncondition - The condition to checkpublic static void assertTrue(boolean condition)
Assert.assertTrue(boolean)
that issues special diagnostics when the assertion fails, if
the given condition supports it.
condition - The condition to check
public static void assertFalse(String message,
boolean condition)
Assert.assertFalse(String,boolean)
that issues special diagnostics when the assertion fails, if
the given condition supports it.
message - The message to use for a failed assertioncondition - The condition to checkpublic static void assertFalse(boolean condition)
Assert.assertFalse(boolean)
that issues special diagnostics when the assertion fails, if
the given condition supports it.
condition - The condition to check
public static String compact(String content,
int threshold,
int prefixLen)
compact("hello
there", 6, 3) will return "hel...ere".
content - The string to shortenthreshold - Strings longer than this will be compacted, while
strings less than or equal to this limit will be returned
unchangedprefixLen - How many characters at the front and back of the
string to keep. This number must be less than or equal to half
the threshold
public static String compact(String content)
content - The string to shorten
public boolean equals(String left,
String right)
String.equals(Object), but is provided for symmetry with
the other comparison predicates provided in this class. For
assertion writing, remember that
Assert.assertEquals(String,String) will
produce more useful information on failure, however.
left - The first string to compareright - The second string to compare
public boolean fuzzyEquals(String left,
String right)
equals(String,String), augmenting its behavior with the
ability to make "fuzzy" string comparisons that ignore things like
differences in spacing, punctuation, or capitalization. It is also
identical to assertFuzzyEquals(String,String), except that it
returns the boolean result of the comparison instead of making a
test case assertion. Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings. For assertion writing, remember that
assertFuzzyEquals(String,String) will
produce more useful information on failure, however.
left - The first string to compareright - The second string to compare
public boolean equalsRegex(String actual,
String expected)
containsRegex(String,String)
instead.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected pattern is the second.
actual - The value to testexpected - The expected value (interpreted as a regular
expression Pattern)
public boolean equalsRegex(String actual,
Pattern expected)
containsRegex(String,Pattern)
instead.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected pattern is the second.
actual - The value to testexpected - The expected value
public boolean fuzzyEqualsRegex(String actual,
String expected)
fuzzyContainsRegex(String,String) instead.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected pattern is the second.
Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
actual - The value to testexpected - The expected value (interpreted as a regular
expression Pattern)
public boolean fuzzyEqualsRegex(String actual,
Pattern expected)
fuzzyContainsRegex(String,String) instead.
Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
actual - The value to testexpected - The expected value
public boolean contains(String largerString,
String substring)
String.contains(CharSequence), but
is provided for symmetry with the other comparison predicates provided
in this class. If the largerString is null, this method returns
false (since it can contain nothing).
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for
public boolean contains(String largerString,
String[] substrings)
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substrings are the second.
largerString - The target to look insubstrings - The substrings to look for (in order)
public boolean fuzzyContains(String largerString,
String substring)
This method makes "fuzzy" string comparisons that ignore things
like differences in spacing, punctuation, or capitalization. Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for
public boolean fuzzyContains(String largerString,
String[] substrings)
This method makes "fuzzy" string comparisons that ignore things
like differences in spacing, punctuation, or capitalization. Use
stringNormalizer() to access and modify the
StringNormalizer object's preferences for comparing
strings.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substrings are the second.
substrings - The substrings to look for (in order)largerString - The target to look in
public boolean containsRegex(String largerString,
String substring)
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for (interpreted as a
regular expression Pattern)
public boolean containsRegex(String largerString,
Pattern substring)
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for
public boolean containsRegex(String largerString,
String[] substrings)
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substrings are the second.
largerString - The target to look insubstrings - An array of expected substrings (interpreted as
regular expression Patterns), which must
occur in the same order in the larger string
public boolean containsRegex(String largerString,
Pattern[] substrings)
largerString - The target to look insubstrings - An array of expected substrings, which must
occur in the same order in the larger string
public boolean fuzzyContainsRegex(String largerString,
String substring)
fuzzyContains(String,String), except
that the first argument is interpreted as a regular expression.
String normalization rules are only appled to the larger string,
not to the regular expression.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for (interpreted as a
regular expression Pattern)
public boolean fuzzyContainsRegex(String largerString,
Pattern substring)
fuzzyContains(String,String), except
that the first argument is interpreted as a regular expression.
String normalization rules are only appled to the larger string,
not to the regular expression.
Note that this predicate uses the opposite parameter ordering from JUnit assertions: The value to test is the first parameter, and the expected substring is the second.
largerString - The target to look insubstring - The substring to look for
public boolean fuzzyContainsRegex(String largerString,
String[] substrings)
fuzzyContains(String,String[]),
except that the second argument is interpreted as an array of regular
expressions. String normalization rules are only appled to the
larger string, not to the regular expressions.
largerString - The target to look insubstrings - An array of expected substrings (interpreted as
regular expression Patterns), which must
occur in the same order in the larger string
public boolean fuzzyContainsRegex(String largerString,
Pattern[] substrings)
fuzzyContains(String,String[]),
except that the second argument is interpreted as an array of regular
expressions. String normalization rules are only appled to the
larger string, not to the regular expressions.
largerString - The target to look insubstrings - An array of expected substrings, which must
occur in the same order in the larger string
|
Last updated: Wed, Apr 1, 2009 12:29 AM EDT | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||