Question on WillOnce() and Times(1)

7,178 views
Skip to first unread message

vijaya sp

unread,
Nov 23, 2015, 2:46:51 PM11/23/15
to Google C++ Mocking Framework
Hi,


I know it works but is it ok to use WillOnce() without using Times(1).

Times(1) says the function should be called just once and WillOnce() is for the return value of the function.

To validate the unit test effectively, we should always use Times(1) before calling WillOnce(). Is my understanding correct?

Thanks!
Vijaya

Billy Donahue

unread,
Nov 23, 2015, 2:53:21 PM11/23/15
to vijaya sp, Google C++ Mocking Framework
Each WillOnce is documented and guaranteed to imply a Times(1) for itself.
You don't need to specify it redundantly.

If Times() is omitted, the cardinality is assumed to be:

- Times(1) when there is neither WillOnce() nor WillRepeatedly();
- Times(n) when there are n WillOnce()s but no WillRepeatedly(), where n >= 1; or
- Times(AtLeast(n)) when there are n WillOnce()s and a WillRepeatedly(), where n >= 0.


Which sounds worse than it is.
Each WillOnce adds 1 to the lower bound of Times, and a WillRepeatedly eliminates the upperbound on Times.

Zhanyong Wan (λx.x x)

unread,
Nov 23, 2015, 4:49:10 PM11/23/15
to Billy Donahue, vijaya sp, Google C++ Mocking Framework
Except for the first WillOnce(), which doesn't change the lower bound (it remains 1).
 
and a WillRepeatedly eliminates the upperbound on Times.

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/CAPdGrqq1O146f8jwcCYZrQPzALxxLaE1f19wESEcqrLU%3D%3D2vVg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Zhanyong
Reply all
Reply to author
Forward
0 new messages