Cheatography
https://cheatography.com
List of functions that are often used
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Annotations
@After |
@AfterClass |
@Before |
@BeforeClass |
@Test |
@Test(expected=Exception.class) |
@Test(timeout=miliseconds) |
JUnit Asserts
assertArrayEquals |
assertEquals |
assertNotEquals |
assertFalse |
assertTrue |
assertNull |
assertNotNull |
assertSame |
assertNotSame |
fail |
Assert methods optionally take an error string as the first parameter, followed by expected and actual values.
Hamcrest Assert
Hamcrest asserts take the form
assertThat(msg, actual, matcher)
Example:
assertThat("Unauthorized User", authorizedUser, hasKey(userName))
|
Core Matchers
allOf, anyOf |
and, both, either, or |
containsString, endsWith, startsWith |
equal |
hasKey |
hasItem, hasItems |
not |
nullValue |
sameInstance |
These are the matchers which are included in JUnit 4
Number Matchers
closeTo |
equalTo |
notEqualTo |
|
|
Array Matchers
arrayContaining |
arrayContainingInAnyOrder |
arrayWithSize |
emptyArray |
Collection Matchers
contains |
containsInAnyOrder |
empty |
emptyCollectionOf |
emptyIterableOf |
hasEntry |
hasKey |
hasValue |
isIn |
isOneOf |
Bean Matchers
hasProperty |
hasPropertyWithValue |
samePropertyValueAs |
Object Matchers
hasToString |
typeCompatibleWith |
String Matchers
equalTo |
equalToIgnoreCase |
equalToIgnoreWhiteSpace |
isEmptyOrNullString |
isEmptyString |
stringContainsInOrder |
|
|
|