Giter Site home page Giter Site logo

onlyfullstack / unit-testing-and-integration-testing-with-spring-boot Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 6.0 65 KB

This repository contains the ways to do the unit testing and mocking in Spring

Home Page: https://onlyfullstack.blogspot.com/

Java 100.00%
junit junit4 spring-unit-testing mockito mockito-junit mockito-junit-test mockito-core mockito-example mockito-framework junit-test

unit-testing-and-integration-testing-with-spring-boot's Introduction

Unit Testing and Mockito Tutorial

In this tutorial, we will understand how to write JUnit test cases. We will understand and implement the below topics.

JUnit Tutorial

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?
    1. Using mvn command
    2. 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
    1. @Test
    2. @Before
    3. @After
    4. @BeforeClass
    5. @AfterClass
    6. @Ignore or @Ignore("Why disabled")
    7. @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
    1. assertEquals()
    2. assertTrue() + assertFalse()
    3. assertNull() + assertNotNull()
    4. assertSame() and assertNotSame()
    5. 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
    1. CoreMatchers.is(T value)
    2. CoreMatchers.not(T value)
    3. CoreMatchers.startsWith(String prefix) & CoreMatchers. endsWith(String suffix)
    4. CoreMatchers.containsString(String substring)
    5. CoreMatchers.notNullValue()
    6. CoreMatchers.sameInstance(T target) & CoreMatchers.instanceOf(Class<?> type)
  • Number Matcher
    1. Matchers.greaterThan(T value) Matchers.greaterThanOrEqualTo(T value)
    2. Matchers.lessThan(T value) Matchers.lessThanOrEqualTo(T value)
  • Collection Matcher
    1. Matchers.empty()
    2. Matchers.hasSize(int size) and Matchers.hasItem(T item)
    3. 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?
    1. try-catch idiom
    2. @Test expected annotation
    3. Junit @Rule

https://onlyfullstack.blogspot.com/2019/02/assert-for-exception-in-junit.html

_____________________________________________________________________________________________

Mockito Tutorial

Mickito 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?
    1. when/then
    2. when/thenThrow
    3. 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:
    1. doNothing/when
    2. doAnswer/when
    3. 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
    1. Object declaration
    2. When the methods are not mocked
    3. When the method is mocked

https://onlyfullstack.blogspot.com/2019/02/mockito-mock-vs-spy.html

unit-testing-and-integration-testing-with-spring-boot's People

Contributors

onlyfullstack avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.