expectations

Calling a method when expected method on mock was invoked

て烟熏妆下的殇ゞ 提交于 2019-12-07 12:52:04
问题 I have the following scenario: class InterfaceA; class InterfaceB; class InterfaceC; class InterfaceA { virtual void foo(InterfaceC&) = 0; }; class InterfaceB { virtual void bar() = 0; }; class InterfaceC { virtual void bla() = 0; }; // MOCKs class MockA : public InterfaceA { public: MOCK_METHOD0(foo, void(InterfaceC&)); }; class MockB : public InterfaceB { public: MOCK_METHOD0(bar, void()); }; class ImplC : public InterfaceC { public: ImplC(InterfaceA& a, Interface& b) : m_a(a), m_b(b) {}

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

纵饮孤独 提交于 2019-12-06 20:45:29
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 Actual: called once - over-saturated and active Google Mock doesn't print the diagnostic on why the

Calling a method when expected method on mock was invoked

大城市里の小女人 提交于 2019-12-05 18:34:39
I have the following scenario: class InterfaceA; class InterfaceB; class InterfaceC; class InterfaceA { virtual void foo(InterfaceC&) = 0; }; class InterfaceB { virtual void bar() = 0; }; class InterfaceC { virtual void bla() = 0; }; // MOCKs class MockA : public InterfaceA { public: MOCK_METHOD0(foo, void(InterfaceC&)); }; class MockB : public InterfaceB { public: MOCK_METHOD0(bar, void()); }; class ImplC : public InterfaceC { public: ImplC(InterfaceA& a, Interface& b) : m_a(a), m_b(b) {} void doSomething() { m_a.foo(*this); } virtual void bla() { m_b.bar(); } }; MockA mockA; MockB mockB;

Testing hash contents using RSpec

青春壹個敷衍的年華 提交于 2019-12-03 14:21:14
问题 I have a test like so: it "should not indicate backwards jumps if the checker position is not a king" do board = Board.new game_board = board.create_test_board board.add_checker(game_board, :red, 3, 3) x_coord = 3 y_coord = 3 jump_locations = {} jump_locations["upper_left"] = true jump_locations["upper_right"] = false jump_locations["lower_left"] = false jump_locations["lower_right"] = true adjusted_jump_locations = @bs.adjust_jump_locations_if_not_king(game_board, x_coord, y_coord, jump

Testing hash contents using RSpec

佐手、 提交于 2019-12-03 04:10:00
I have a test like so: it "should not indicate backwards jumps if the checker position is not a king" do board = Board.new game_board = board.create_test_board board.add_checker(game_board, :red, 3, 3) x_coord = 3 y_coord = 3 jump_locations = {} jump_locations["upper_left"] = true jump_locations["upper_right"] = false jump_locations["lower_left"] = false jump_locations["lower_right"] = true adjusted_jump_locations = @bs.adjust_jump_locations_if_not_king(game_board, x_coord, y_coord, jump_locations) adjusted_jump_locations["upper_left"].should == true adjusted_jump_locations["upper_right"]

PHPUnit mock with multiple expects() calls

筅森魡賤 提交于 2019-12-01 06:33:49
Using PHPUnit, I wonder how we can have multiple expectation from the same stub/mock. For example, I want to test that the mock will have the method display() called and return NULL. I also want to test that the method process() will be called. In fact my test is called testProcessIsCalledIfDisplayReturnNull() . So I need to setup 2 expectations on the same mock object, and the manual doesn't really help about that :( If you know, that method is called once use $this->once() in expects(), otherwise use $this->any() $mock = $this->getMock('nameOfTheClass', array('firstMethod','secondMethod',

PHPUnit mock with multiple expects() calls

家住魔仙堡 提交于 2019-12-01 03:44:13
问题 Using PHPUnit, I wonder how we can have multiple expectation from the same stub/mock. For example, I want to test that the mock will have the method display() called and return NULL. I also want to test that the method process() will be called. In fact my test is called testProcessIsCalledIfDisplayReturnNull() . So I need to setup 2 expectations on the same mock object, and the manual doesn't really help about that :( 回答1: If you know, that method is called once use $this->once() in expects()