Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/multicatch/mockgiven
Easy BDD on mocks
https://github.com/multicatch/mockgiven
Last synced: 28 days ago
JSON representation
Easy BDD on mocks
- Host: GitHub
- URL: https://github.com/multicatch/mockgiven
- Owner: multicatch
- License: mpl-2.0
- Created: 2019-07-23T09:52:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-15T13:33:43.000Z (almost 4 years ago)
- Last Synced: 2023-03-11T04:55:42.246Z (over 1 year ago)
- Language: Java
- Size: 104 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MockGiven
[![Build Status](https://travis-ci.org/multicatch/MockGiven.svg)](https://travis-ci.org/multicatch/MockGiven)
[![Coverage Status](https://coveralls.io/repos/github/multicatch/MockGiven/badge.svg)](https://coveralls.io/github/multicatch/MockGiven)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)MockGiven is an aggregation of Mockito, JGiven and AssertJ tools. It simplifies writing tests, which heavily depend on mocking.
### Why?
Because I'm too lazy for writing 4 separate classes for testing a simple implementation.
For me using JGiven was just too much and while JGiven surely generates nice reports, it felt like using an excavator to plant flowers.
So as a result I combined 3 tools that I use the most and made another tool (duh) that makes it easy to create tests.### Benefits
* Nice reports thanks to JGiven
* Mocking thanks to Mockito
* Fluent assertions thanks to AssertJ
* No need to declare given stages for mocking
* No need to declare when stage for running a single line of code
* No need to declare then stage for wrapping assertions
### ExamplesTaken from mockgiven-junit-example
```Java
@Mock
private NumberProvider numberProvider;@InjectMocks
private QuirkyCalculator quirkyCalculator;@Test
public void numberShouldBeExponentiated() {
given("a number provider", numberProvider.provide()).returns(BigInteger.TEN);
when("a number is exponentiated to the power of 2").by(() -> quirkyCalculator.exponentiate(2));
then().assertUsing(BigIntegerAssert.class)
.thatResult()
.isEqualTo(100);
}```
and this generates following report
```text
Number should be exponentiatedGiven a number provider returns 10
When a number is exponentiated to the power of 2
Then result is equal to 100
```### FAQ
#### Is it stable?No, I'm still testing it and thinking of new features, create a feature request if you have any good ideas.
Also, testing it would help.
#### Why should we stick to this instead of JGiven?
You maybe shouldn't. Or ought to. It's not like my tool is any better than JGiven, it simplifies some things for me and I think it can help you too.
#### What if Mockito or AssertJ aren't enough for my given and then?
Just use MockScenarioTest and create "traditional" JGiven tests.
#### Why you don't support JUnit 5?
Because JGiven doesn't support JUnit Jupiter, the only support it has is *experimental*.
### License
This software is licensed under [Mozilla Public License Version 2.0](LICENSE)