Sunday 18 February 2018

Hamcrest tutorial

Basics

      Introduction to Hamcrest
      Hello World Application

Test null values

      Match null values
      nullValue: Creates a matcher that matches if examined object is null
      notNullValue : Creates a matcher that matches if examined object is not null

Matchers to work with strings

      Hamcrest: Matchers to work with strings
      containsString: match sub string
      startsWith: Check whether string starts with given string
      endsWith: Check whether string ends with given string
      equalToIgnoringCase: check equality of strings by ignoring case
      equalToIgnoringWhiteSpace: check equality of strings by ignoring case and white spaces
      isEmptyString: Match if the string is empty
      isEmptyOrNullString: Match if the string is empty or null
      stringContainsInOrder: Matches a string against all the substrings

Work with Arrays

      Matchers to work with arrays
       array: Match every element of array with specific matcher
      hasItemInArray: Check the existence of item in the array
      arrayContaining: Match each item in the array
      arrayContainingInAnyOrder: Check array euality, order doesn't matter
      arrayWithSize: Check array length
      emptyArray: match empty array

Compare Objects

      Matchers to compare objects
      greaterThan: check whether given object is greater than this value
      greaterThanOrEqualTo: check whether given object is greater than or equal to this value
      
      lessThanOrEqualTo: Check whether object is <= other object
      comparesEqualTo: Check objects equality

Marchers to check instances

      Marchers to check instances
      instanceOf: Check whether object is instance of class or not
      sameInstance: objects equality checker
      theInstance: objects equality checker
      equalTo: objects equality using equals method

Matchers to work with collections

      Matchers to work with collections
      everyItem: All elements must match to given matcher
      hasItem: Check for the existence of at least one item
      hasItems: Check for the existence of multiple items
      hasSize: Checks the size of collection
      empty: Check emptiness of collection
      emptyCollectionOf: Check the emptiness of collection
      emptyIterable: Check the emptiness of iterables
      emptyIterableOf: Check the emptiness of iterable
      contains: Check for the existence of elements in the collection
      containsInAnyOrder: Search the elements of collection (order doesn’t matter)
      iterableWithSize: Check the size of iterable
      hasEntry: Check for the entry in map
      hasKey: Check for the existence of key
      hasValue: Check the existence of value in map
      isIn: Check the object existence in the collection
      isOneOf: Matches of altest one element matches
      IsIterableContainingInOrder: test the ordering of collection or list elements

Combining matchers

      Combining matchers
      allOf: Match against all the matchers
      both: Match against two matchers
      either: match against either of the matcher
      anyOf: match against any one of the matcher

Working with classes and objects

      Working with classes and objects
      hasProperty: Check whether given object has specific property or not
      isA: Check whether object is of given type
      typeCompatibleWith: Check the compatibility of one type with other
      samePropertyValuesAs: Check two beans properties
      any: Match an object that is instance of class

Working With Numbers

      closeTo: Working with numbers

Previous                                                 Next                                                 Home

No comments:

Post a Comment