expectations

PHPUnit Mock Objects never expect by default

ⅰ亾dé卋堺 提交于 2020-08-27 05:54:11
问题 Is there a way to tell a phpunit mock object to never expect the method calls if there are no formally defined expectations for them? 回答1: In my opinion it's not got idea to never expectation for every method. So phpunit doesn't have any functionality. Can should use "never" expectations only if you want totally ensure that some method won't be called. Anyway you can use some matchers to get closer your goal. Examples: Never expectations for all object's methods (fails if any of mocked

Interleaving EXPECT_CALL()s and calls to the mock functions

不想你离开。 提交于 2020-05-15 04:06:59
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

Interleaving EXPECT_CALL()s and calls to the mock functions

前提是你 提交于 2020-05-15 04:03:35
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

Interleaving EXPECT_CALL()s and calls to the mock functions

戏子无情 提交于 2020-05-15 04:03:25
问题 The Google Mock documentation says: Important note: Google Mock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined . In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions. Does anyone know any details behind this restriction? I have a number of unit tests which definitely violate this rule but seem to function properly, however. 回答1: I have to disagree with @Marko Popovic's assessment, and believe what he's

How to expect some (but not all) arguments with RSpec should_receive?

假装没事ソ 提交于 2020-04-07 02:34:40
问题 class Foo def bar(a, b) ... Foo.should_receive( :bar ) expects bar to be called with any arguments. Foo.should_receive( :bar ).with( :baz, :qux ) expects :baz and :qux to be passed in as the params. How to expect the first param to equal :baz, and not care about the other params? 回答1: Use the anything matcher: Foo.should_receive(:bar).with(:baz, anything) 回答2: For Rspec 1.3 anything doesn't work when your method is receiving a hash as an argument, so please try with hash_including(:key => val

How to expect some (but not all) arguments with RSpec should_receive?

南楼画角 提交于 2020-04-07 02:34:35
问题 class Foo def bar(a, b) ... Foo.should_receive( :bar ) expects bar to be called with any arguments. Foo.should_receive( :bar ).with( :baz, :qux ) expects :baz and :qux to be passed in as the params. How to expect the first param to equal :baz, and not care about the other params? 回答1: Use the anything matcher: Foo.should_receive(:bar).with(:baz, anything) 回答2: For Rspec 1.3 anything doesn't work when your method is receiving a hash as an argument, so please try with hash_including(:key => val

Sum all possible values a player can have in a two player game

折月煮酒 提交于 2019-12-12 04:14:13
问题 This is a classical game where two players play following game: There are n coins in a row with different denominations. In this game, players pick a coin from extreme left or extreme right (they blindly pick from any extreme with a probability of .5, both of them are dumb). I just want to count the expected sum of player who starts the game. For this I want to sum up all the possible combinations of values a player can have. I am using a recursive solution which sums up all the possible

expected ';' at the end of declaration list

和自甴很熟 提交于 2019-12-11 20:14:40
问题 error:- expected ';' at the end of the declaration list #import <UIKit/UIKit.h> @interface ViewController : UIViewController { float number; error:- expected ';' at the end of the declaration list float result; int currentoperation; __weak IBOutlet UILabel *label; } - (IBAction)canceloperation:(id)sender; - (IBAction)cancelnumber:(id)sender; - (IBAction)buttonoperation:(id)sender; - (IBAction)buttonnumber:(id)sender; @end Please fix this code. 回答1: The OP's question is stated quite bad, but

How to set Expect to a Extension method in Rhino Mocks 3.6

Deadly 提交于 2019-12-11 08:15:56
问题 Good afternoon I have a class and it has an associated extension method. public class Person{ public int ID {get;set} public string Name {get;set} } Extension method: public static class Helper { public static int GetToken(this Person person){ int id = 0; //Something here is done to read token from another service... return id; } } Now I am trying to use Rhino and test this method public void readPersonToken(int personId) { var person = Person.GetPersonInfo(personId);//we consume a service

GoogleMock: how to expect precisely one call with a certain argument, and see diagnostic on failure?

五迷三道 提交于 2019-12-08 06:11:17
问题 Maybe a finesse question, my problem is that if I write: EXPECT_CALL(mock, handleMessage(_)).Times(0); // expectation #1 EXPECT_CALL(mock, handleMessage(Pointee(IsLike(aSpecificMessage)))); // expectation #2 ... and method handleMessage is called once, but with a different argument (not aSpecificMessage ), then the failure looks like: Mock function called more times than expected - returning default value. Function call: handleMessage(0x8b5378) Returns: false Expected: to be never called