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).
Questions tagged [expectations]
121 questions
2
votes
1 answer
Is there a way to get a stack trace from rspec when a method is unexpectedly called more times than specified?
I setup a mock object and told it to expect a check for nil and to return false:
status = double('status')
status.should_receive(:nil?).and_return(false)
I only expect the call to nil? to occur once, but I got an error in my rspec test, saying that…

user1476905
- 53
- 5
2
votes
1 answer
Recording expectations in a method called from the instance initialiser
I don't really understand the behaviour of the tests below. Looking at it, test_OK and test_Not_OK are strictly equivalent - the only difference is that test_OK has "inlined" callMethod.
However, test_OK passes whereas test_Not_OK fails. Is there a…

assylias
- 321,522
- 82
- 660
- 783
1
vote
1 answer
Expected response to be a <:redirect>, but was <401>
I've recently started converting some of the standard requests I have in my application to XHR (Ajax) requests. I'm in the process of updating my RSpec tests to reflect this but am encountering this error message:
Expected response to be a…

Gav
- 11,062
- 7
- 33
- 35
1
vote
1 answer
JMockit - Expectations and static methods
I'm trying to mock a method to have it return one specific object:
private static final String PARAM = "somevalue";
...
@Test
public void jmockit() {
final PojoClass dfault = new PojoClass();
new NonStrictExpectations() {
…

Grasshopper
- 1,749
- 1
- 14
- 30
1
vote
1 answer
What is the cause for this SecurityException when I try to include the expectations for a mock obejct?
I'm trying to use mock objects in my testing. However the same exception is being thrown when I try to list the expectations of the mock object.
The following is the stack trace of the exception:
java.lang.SecurityException: class…

ict1991
- 2,060
- 5
- 26
- 34
1
vote
1 answer
Expectation of a product in python sympy
In python sympy I have the following code
from sympy.stats import P, E, variance, covariance, Normal
mu, sigma = symbols('mu sigma')
epsilon_t = Normal('epsilon_t', 0, sigma)
epsilon_t1 = Normal('epsilon_t+1', 0, sigma)
which defines two…

Daniel
- 167
- 9
1
vote
2 answers
1
vote
0 answers
JMockit mock constructor in Expectations
I'm trying to set a result on a constructor call in an Expectations block, but the constructor call in the tested code doesn't return the result I'm setting. There must be a different way to do this, the code below is my attempt, and fails on the…

eriksmith200
- 2,159
- 5
- 22
- 33
1
vote
2 answers
How to set Expect to a Extension method in Rhino Mocks 3.6
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…

Junior Mayhé
- 16,144
- 26
- 115
- 161
1
vote
0 answers
Jmockit How to match 'any' parameter type for Class clazz
Using jmockit, i am creating new expectation
new Expectations(){{
ConfigurationService.get(anyString,****);
}};
of static method
public static T get(String key, Class clazz) {
How to match 'any' parameter type for Class…

Melad Basilius
- 3,847
- 10
- 44
- 81
1
vote
1 answer
Why don't array include checks work as expected in chai.js?
I'm using chai.js expectations with the mocha JS test framework. I'm trying to test inclusion of objects in arrays but it appears the includes behavior supported by chai in their documentation doesn't work as I expect:
The example on the chai…

scorpiodawg
- 5,612
- 3
- 42
- 62
1
vote
3 answers
Java Mockito when accept arguments but conditionally
I am writing a test case using Mockito, and have to write expectation for a method (signature shown below)
public Object process(Employee e);
In my test class, I have to simulate my expectations as follows:
when(someClass.process("any Employee with…

pankaj_ar
- 757
- 2
- 10
- 33
1
vote
1 answer
IllegalArgumentException: Invalid conditional statement inside expectation block
I have a problem with an Expectations block I have written in my test case:
new Expectations() {
{
mFindHandlerMock.findAll((Model) any, (Set) any, false);
if (!pWithRealData) {
result = Collections.emptySet();
…

nano_nano
- 12,351
- 8
- 55
- 83
1
vote
3 answers
java.lang.Exception: Test class should have exactly one public zero-argument constructor:
I have a class : Function Library where I am instantiating the webdriver instance in constructor as below
public class FunctionLibrary {
public WebDriver driver;
public FunctionLibrary(WebDriver driver)
{
driver = new…

Shilpa
- 75
- 2
- 5
- 12
1
vote
0 answers
Is there a way to find unused expectations in jMock?
We use jMock for a lot of our Java tests. In some test classes, most of the tests work the same way, so common expectations end up in a setUp() method.
Quite often, some of the expectations in the setUp() method are only used for some of the tests.…

Hakanai
- 12,010
- 10
- 62
- 132