In this tutorial, we will understand how to write JUnit test cases. We will understand and implement the below topics.
Part 1 - What is Unit Testing? In this tutorial, we will understand below topics -
- What is Unit Testing?
- Unit Testing Method
- When is it performed?
- Who performs it?
- How to perform it?
https://onlyfullstack.blogspot.com/2019/02/what-is-unit-testing.html
Part 2 - ** What is JUnit? How to use JUnit? In this tutorial, we will understand below topics -
- What is Junit?
- How to use Junit?
- Where should the test be located?
- How to execute JUnit tests?
- Using mvn command
- Using Eclipse Run as > JUnit Test
- Eclipse Optimize Imports to Include Static Imports
https://onlyfullstack.blogspot.com/2019/02/what-is-junit-how-to-use-junit.html
Part 3 - Annotations used in JUnit In this tutorial, we will understand below topics -
- How to define a test in JUnit?
- Annotations used in Junit
- @Test
- @Before
- @After
- @BeforeClass
- @AfterClass
- @Ignore or @Ignore("Why disabled")
- @Test (expected = Exception.class)
https://onlyfullstack.blogspot.com/2019/02/annotations-used-in-junit.html
Part 4 - JUnit Assert Methods In this tutorial, we will understand below topics -
- Assert Methods
- assertEquals()
- assertTrue() + assertFalse()
- assertNull() + assertNotNull()
- assertSame() and assertNotSame()
- assertThat()
https://onlyfullstack.blogspot.com/2019/02/junit-assert-methods.html
Part 5 - Complete guide for Hamcrest JUnit In this tutorial we will understand below topics-
- Hamcrest Matcher Tutorial
- The Core Matchers
- CoreMatchers.is(T value)
- CoreMatchers.not(T value)
- CoreMatchers.startsWith(String prefix) & CoreMatchers. endsWith(String suffix)
- CoreMatchers.containsString(String substring)
- CoreMatchers.notNullValue()
- CoreMatchers.sameInstance(T target) & CoreMatchers.instanceOf(Class<?> type)
- Number Matcher
- Matchers.greaterThan(T value) Matchers.greaterThanOrEqualTo(T value)
- Matchers.lessThan(T value) Matchers.lessThanOrEqualTo(T value)
- Collection Matcher
- Matchers.empty()
- Matchers.hasSize(int size) and Matchers.hasItem(T item)
- Matchers. hasKey(K key), Matchers.hasValue(V value) & Matchers.hasEntry(K key, V value)
https://onlyfullstack.blogspot.com/2019/02/complete-guide-for-hamcrest-junit.html
Part 6 - Assert for an exception in JUnit In this tutorial, we will understand below topics-
- How do you assert that a certain exception is thrown in JUnit 4 tests?
- try-catch idiom
- @Test expected annotation
- Junit @Rule
https://onlyfullstack.blogspot.com/2019/02/assert-for-exception-in-junit.html
_____________________________________________________________________________________________
Mockito Tutorial
In this tutorial, we will understand how to use Mockito framework. We will understand and implement the below topics.
Part 1 - What is Mockito? In this tutorial, we will understand below topics -
- What is a Mock Object?
- When should I mock?
- Mockito Framework
- Enable Mockito Annotations
- How to Mock Object with @Mock & @InjectMock annotations in Spring application?
https://onlyfullstack.blogspot.com/2019/02/what-is-mockito.html
Part 2 - How to mock methods with Mockito?
- How to mock methods?
- when/then
- when/thenThrow
- when/thenAnswer
https://onlyfullstack.blogspot.com/2019/02/how-to-mock-methods-with-mockito.html
Part 3- How to mock void methods with Mockito
- Mocking Void Methods
- Three ways to mock the void method:
- doNothing/when
- doAnswer/when
- doThrow/when
https://onlyfullstack.blogspot.com/2019/02/how-to-mock-void-methods-with-mockito.html
Part 4 - How to verify mocks in Mockito
- Simple verify method
- Variations in verify method
- Verify with the number of times
- Mockito Verify Order of Invocation
https://onlyfullstack.blogspot.com/2019/02/how-to-verify-mocks-in-mockito.html
Part 5 - **** Mockito Mock vs Spy
- Mockito Mock vs Spy
- Object declaration
- When the methods are not mocked
- When the method is mocked
https://onlyfullstack.blogspot.com/2019/02/mockito-mock-vs-spy.html