Provide way to assert completed calls without using Repeated class
See original GitHub issueAs mentioned by @jholovacs in #808, the Repeated
in A.CallTo(() => f.Boo()).MustHaveHappened(Repeated.Exactly.Once)
could be construed as meaning “Boo must have happened, and then it must have been repeated, for a total of two calls”. After much discussion, we’ve resolved to provide alternative methods and eventually deprecate and remove Repeated
.
As noted in that issue, we’ll introduce the following API:
MustHaveHappened() // as today
MustNotHaveHappened() // as today
MustHaveHappenedOnceExactly()
MustHaveHappenedOnceOrMore()
MustHaveHappenedOnceOrLess()
MustHaveHappenedTwiceExactly()
MustHaveHappenedTwiceOrMore()
MustHaveHappenedTwiceOrLess()
MustHaveHappened(3, Times.Exactly)
MustHaveHappened(3, Times.OrMore)
MustHaveHappened(3, Times.OrLess)
MustHaveHappenedANumberOfTimesMatching(n => n %2 == 0) // the argument is an Expression<Func<int, bool>>
Times
is a new class.
This satisfies the following goals:
- Eliminates the confusion over the exact semantics of
Repeated
- Retains
MustHaveHappened()
andMustNotHaveHappened()
, which are the most popular methods in use today - Improves discoverability, even over the existing
Repeated
mechanism - Provides a consistent, natural word ordering (to contrast with
Repeated.Times(3)
) - Does not require an extension method on
int
- Avoids forgettable terminal operators (e.g.
MustHaveHappened(3).Times
, where theTimes
could be forgotten) - Allows for a soft transition away from the current methods; the
Repeated
variants can live for a major release or two and be deprecated in 5.0.0 and removed in 6.0.0.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top Results From Across the Web
java - How do I assert equality on two classes without an ...
With JUnit 5, there is a method called Assertions.assertAll() which will allow you to group all assertions in your test together and it...
Read more >Stop requiring only one assertion per unit test: Multiple ...
Assertion Roulette doesn't mean that multiple assertions are bad. ... While clearly a no-op, this implementation passes all tests.
Read more >Single Assert Call for Multiple Properties in Java Unit Testing
Learn three approaches to verifying multiple properties in one assert call using JUnit5 and AsssertJ.
Read more >Is it OK to have multiple asserts in a single unit test?
The main reason people like to have multiple Assertions is they are trying to have a one [TestFixture] class for each class being...
Read more >Unit Testing Asynchronous Code in C# | CodeGuru.com
Observe that await is a unary operator, with the operand being the name of the method to be awaited. Consider the following C#...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One concern I’d have with deprecating in 4.4.0 is that any consumers of the old API who have
TreatWarningsAsErrors
will find themselves unable to build when they pick up 4.4.0. This may be a bit of surprise for a minor release. Of course, one could say that they had it coming by turning on that flag…@Mertsch, by all means guide people to the new APIs. I would. And we have an update to the Analyzer in the works that will also guide them as soon as it’s done.
The main reason we did not deprecate the APIs yet is that that can be considered a breaking change. It’s common in the OSS framework ecosystemcitation needed to deprecate an API in a major release and remove it in the following major release. Accordingly, we should deprecate in 5.0.0 and remove in 6.0.0. We don’t yet have any timing around a 5.0.0 release, but it is something we could investigate.