Skip to content

mengdaming/mocks-fakes-spies-and-stubs-kata

 
 

Repository files navigation

Mocks, Fakes, Spies and Stubs Kata

This is an adaptation of the original kata available at github.com/aleixmorgadas/mocks-fakes-spies-and-stubs-kata

Recommended Reading

Setup Environment

  1. Clone the repository
    git clone https://stash.murex.com/scm/xps/mocks-fakes-spies-and-stubs-kata.git
  2. Check that all tests are green
    ./gradlew test

How is the kata structured?

  • kata.domain.film: Test-Doubles examples made with Mockito and hand-made examples.
  • kata.domain.user: Support domain to represent the UserId
  • kata.domain.rate: Actual kata
  • kata.support: InMemoryRepositories

Running the kata

1 - Implement RateService tests using different kinds of test doubles

Check the tests in kata.domain.rate.

You will see RateServiceTest_Fake and RateServiceTest_Mock_Stub_Spy. Implement each Test following the named pattern.

Info: Remember that using two different Test Double types in the same test is allowed.

2 - Alter the behaviour of RateService and observe impacts on the tests

For each of the following cases, observe which tests turn red and which remain green.

  1. Introduce some bugs
  2. Refactor by adding RateRepository.save(rate)
  3. Refactor by adding RateRepository.findByUser(userId) for optimisation
  4. Decreased the notification threshold by one

3 - Replace FilmService mock with a fake

In RateService test setups, use FilmRepositoryInMemory instead of mocking FilmService. What do you observe?

4 - Test Doubles Pros, Cons and Fixes

Fill a table listing the pros, cons and fixes for each type of Test Double

Test Double Family Pros Cons Fixes
Mocks, Spies, Stubs
Fakes

Session Quick Retrospective

You can fill it from here

Support Docs

About

Kata to practice the usage of different test-doubles

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%