Questions tagged [expectations]

defines a set of expected and/or allowed method/constructor invocations on the mocked types/instances that have been made available to the test through mock fields and/or mock parameters (e.g., in JMockit).

121 questions
70
votes
4 answers

Testing hash contents using RSpec

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 …
steve_gallagher
  • 3,778
  • 8
  • 33
  • 51
67
votes
3 answers

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

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…
B Seven
  • 44,484
  • 66
  • 240
  • 385
22
votes
2 answers

JMockit Expectation API : How to throw an exception upon method/constructor invocation

While using JMockit I want to throw an exception upon a constructor invocation like this: new Expectations(){ { new FirefoxDriver();//Want to throw IllegalStateException here but how? } };
Affan Hasan
  • 334
  • 1
  • 4
  • 16
16
votes
2 answers

What is the difference between rhino-mocks stub and expect

What is the difference between rhino-mocks stub and expect here: Looks to me that they behave exact the same? mockContext.Stub(x => x.Find()) .Return(new List() { new Blog() { Id = 1, Title = "Test" } …
Nikos
  • 7,295
  • 7
  • 52
  • 88
12
votes
2 answers

How to ignore extra messages with RSpec should_receive?

Spec: before do Logger.should_receive( :write ).with 'Log message 1' end it 'works' do get '/' end Sinatra App: get '/' Logger.write( 'Log message 1' ) Logger.write( 'Log message 2' ) end This spec fails because of 'Log message 2'.…
B Seven
  • 44,484
  • 66
  • 240
  • 385
10
votes
2 answers

Interleaving EXPECT_CALL()s and calls to the mock functions

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…
Jordan
  • 1,375
  • 14
  • 17
8
votes
2 answers

PHPUnit Mock Objects never expect by default

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?
7
votes
2 answers

PHPUnit mock with multiple expects() calls

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…
FMaz008
  • 11,161
  • 19
  • 68
  • 100
7
votes
1 answer

Jasmine : spy on a function called X times, and get the n-th call

I can't seem to find a solution online. Here is a sample of code so you get the issue : // Spy on the wanted function spyOn(object, 'myFunction'); // Call it 3 times with different parameters object.myFunction(''); object.myFunction('',…
user4676340
7
votes
2 answers

c++ gtest print additional information in the end of a test when and only when the test fails

I want to do somethink like this: TEST(MyTestFixture, printAfterExpectationFailure) { const string request("bring me tea"); const string&& response = sendRequestAndGetResponse(request); checkResponseWithExpectarions1(response); …
baziorek
  • 2,502
  • 2
  • 29
  • 43
6
votes
2 answers

Google Mock: why is a partial ordering of expectations harder to satisfy than a total ordering?

I'm mostly using ordered expectations with GoogleMock, so all EXPECT_CALLs were written inside the scope of a testing::InSequence object. Now I want to relax the ordering so I split the expectations in 2 sequences. You would say the test should…
haelix
  • 4,245
  • 4
  • 34
  • 56
5
votes
1 answer

Calling a method when expected method on mock was invoked

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; }; //…
Martin
  • 968
  • 3
  • 10
  • 19
5
votes
1 answer

iOS8 bad access exception when doing unit tests with expectation

I have a series of unit tests written using XCTest framework. These were originally created on iOS7, then executed in xCode6 on iOS8 device. The tests are executing in sequence, but then I get EXC_BAD_ACCESS (code= 1, address 0xc) for the following…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
4
votes
1 answer

How to implement fixtures in clojure expectations?

I have recently started using the Clojure test framework expectations. As part of my test, I have a data set that I want to reset to its original value before the start of a new test/expect statement. In clojure.test, I would just create a fixture…
3
votes
1 answer

XCTWaiter().wait with XCTestExpectation and NSPredicate seems to fail

I am trying to write unit tests where I want my test case to wait for a variable in a certain class to change. So I create an expectation with a predicate and wait for the value to change using XCTWaiter().wait(for: [expectation], timeout: 2.0),…
gbroekstg
  • 1,055
  • 1
  • 10
  • 19
1
2 3
8 9