question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide way to assert completed calls without using Repeated class

See original GitHub issue

As 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:

  1. Eliminates the confusion over the exact semantics of Repeated
  2. Retains MustHaveHappened() and MustNotHaveHappened(), which are the most popular methods in use today
  3. Improves discoverability, even over the existing Repeated mechanism
  4. Provides a consistent, natural word ordering (to contrast with Repeated.Times(3))
  5. Does not require an extension method on int
  6. Avoids forgettable terminal operators (e.g. MustHaveHappened(3).Times, where the Times could be forgotten)
  7. 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
blairconradcommented, Feb 6, 2018

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…

1reaction
blairconradcommented, Feb 6, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found