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
3
votes
0 answers

Clear JMockit expectations after a test or a testclass

We are having an old codebase with few tests mocking global static object. That influences other tests that fail if being called in a same testsuite (the same JVM) after the test which mocks static property. There's a lot of work involved in…
Michal
  • 384
  • 3
  • 8
3
votes
1 answer

JMockit - Expectations - matching invocation of method that includes mocked object as argument

I am using JMockit to test an application (Java 8, Junit 4.12, JMockit 1.17). I have some code which is supposed to upload some data to a list of endpoints. The class that actually performs an upload to an endpoint is called PlatformDataUploader.…
user3441604
  • 582
  • 7
  • 23
3
votes
1 answer

JUnit test case failure with JMockit java.lang.IllegalStateException: Invalid context for the recording of expectations

@Test public void testGetOnlyNewPartitions() throws Exception { setUp(); new Expectations(){ HiveUtil hiveUtil; { HiveUtil.getInstance(); returns(hiveUtil); hiveUtil.getAllpartitions(oldTable);…
Nikhil Gupta
  • 31
  • 1
  • 3
3
votes
2 answers

NotImplementedException in Hippomock's MockRepository::BasicRegisterExpect

While trying to register an expectation using Hippomock's MockRepository::ExpectCall I encounter the NotImplementedException exception at MockRepository::BasicRegisterExpect's following line which I admittedly do not understand: if ((unsigned…
Roland Sarrazin
  • 1,203
  • 11
  • 29
3
votes
2 answers

rspec - how to test for a model attribute that is not a database column

I have an Active Record based model:- House It has various attributes, but no formal_name attribute. However it does have a method for formal_name, i.e. def formal_name "Formal #{self.other_model.name}" end How can I test that this method…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
3
votes
1 answer

Set an expectation without mocking anything

Using MiniTest::Spec and Mocha: describe "#devices" do it "scopes the devices by the provided :ip_list" do ips = 'fast tests ftw!' ds = DeviceSearch.new ip_list: ips Device.expects(:scope_by_ip_list).once.with(ips) …
chadoh
  • 4,343
  • 6
  • 39
  • 64
2
votes
1 answer

using assertRaises - handling propagated exceptions

I have some code where I'm testing for a wrapped exception, when it failed and the exception propagated I thought the error message and back trace wasn't verbose enough, primarily because it didn't tell me what was expected vs. the test, I would…
2
votes
1 answer

Invalid place to record Expectations

I'm using JMockit 1.14 with Junit 4. private void method() { new NonStrictExpectations() { { firstObject.getLock(); returns(new Lock()); secondObject.getDetails(); result =…
John Smith
  • 844
  • 8
  • 26
2
votes
2 answers

gmock Segmentationfault on EXPECT_CALL

On cygwin, EXPECT_CALL gives segmentation fault. Back trace shows: Program received signal SIGSEGV, Segmentation fault. 0x004538e2 in join (ptr=0x61230494 , this=0x8003aedc) at…
Ray Xu
  • 51
  • 2
  • 6
2
votes
0 answers

Explicitly verifying a mocha expectation after it's been called

I am using Mocha::Hooks#mocha_verify in the after_scenario spinach hook which works fine for some cases. However, there are many times when I want to verify an expectation after a value has been updated on a piece of data. For example, class MyModel…
gabe
  • 1,873
  • 2
  • 20
  • 36
2
votes
0 answers

RSpec argument contraints for any number of anything

How to write correctly the expectation with matching first argument and ignoring other arguments? There can be any number of other arguments. expect_any_instance_of(MyClass).to receive(:my_method).with('Argument', any_args) I got this…
mirelon
  • 4,896
  • 6
  • 40
  • 70
2
votes
1 answer

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

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…
haelix
  • 4,245
  • 4
  • 34
  • 56
2
votes
1 answer

Calculation of Expected number of inversions in a changing array

Problem: We have an array of size n and we are am allowed to perform at most K operations where each operation can be decrease the number of inversions by 1. make a random shuffle of the whole array. My problem is to perform the K operations in…
v78
  • 2,803
  • 21
  • 44
2
votes
1 answer

How does RSpec allowing and expecting producing unexpected results for multiple calls

I'm trying to write a test to prevent you from doing the same thing twice (in this case, playing on the same square twice in tictactoe), but RSpec syntax is confusing me and I can't see a solution in their docs. I've tried a few approaches with no…
Arepo
  • 825
  • 1
  • 9
  • 23
2
votes
1 answer

Meaning Logarithm Likelihood in Exp. Maximization algorithm

I have implemented the exp. maximization algorithm and it converges and returns the values of mu and sigma correctly, I have checked with various examples. I have tried to plot the log-likelihood, but I don't know how it will look in the correct…
flatronka
  • 1,061
  • 25
  • 51
1
2
3
8 9