Questions tagged [partial-mocks]
32 questions
10
votes
3 answers
Partial Mocking As Code Smell?
Why is there so much hating going on about 'partial mocking' and the code that requires it?
Here's an (theoretical) example implementation:
public ComplexResult1 operationA(Stimulus a) {
{
...
result = ...;
}
…

Nelz
- 111
- 5
8
votes
1 answer
Partial mocking a class internal method with Moq
I have a class that contains a public method, that relies on a internal method in order to properly return its value.
Let's consider the following class and test file:
public class ClassUnderTest
{
public string NotMockedPublicMethod()
{
…

Caio Cunha
- 23,326
- 6
- 78
- 74
5
votes
3 answers
how to partial mock public method using PowerMock?
Following is my class
public class SomeClass {
public ReturnType1 testThisMethod(Type1 param1, Type2 param2) {
//some code
helperMethodPublic(param1,param2);
//more code follows
}
public ReturnType2…

maverick
- 549
- 2
- 10
- 18
4
votes
1 answer
When does Mockito.mock create a partial mock instead of a "full" mock?
Given this code:
// Subject.kt
open class Subject(var x: Int) {
constructor(): this(42) {
println("made it")
}
fun doit() {
x += 1
println("did it: $x")
}
}
// Tests.kt
import…

Aethon Invictus
- 275
- 2
- 9
4
votes
2 answers
Unit-testing with mockito (partial mocking)
I have a problem with Mockito.
Is it possible to do such a thing:
ClassX x = mock(ClassX.class)
when(x.methodB()).thenReturn("toto");
String result = x.methodA();
I'm working with Mockito 1.7.
I saw there was a "spy" system but they say it's not…

Sebastien Lorber
- 89,644
- 67
- 288
- 419
4
votes
2 answers
How to match 'any' parameter type while mocking private method in Jmockit
I have a problem while using jmockit for the following scenario. Did a research on the web, but couldn't locate the answers yet.
In the record phase, I am setting the expectation on an object that is partially mocked. While doing it, I would like…

Alex Vincent
- 41
- 1
- 1
- 5
3
votes
1 answer
How to partial mock a method that throws exceptions using Mockito?
It's useful to test exception handling. In this specific case, I have a extractor that will do a specific task when an exception is thrown while unmarshaling a specific class.
Example Code
Below is a simplified example of the code. The production…

Pete
- 3,246
- 4
- 24
- 43
3
votes
1 answer
Stub setter in Rhino Mock partial mock
I'm following the accepted answer in this question but I'm getting a NullReferenceException.
What I need is having a partial mock stub a property (both getter and setter) to behave like a stub (as a simple automatic property). Currently I am able to…

jorgehmv
- 3,633
- 3
- 25
- 39
2
votes
1 answer
How to set up an object with InternalsVisibleTo in an assembly to implement partial mocks with Rhino Mocks 3.6
Below, I have code for an object that I would like to test. It is in an assembly called Business and I have added the attributes in the AssemblyInfo.cs to make internals visible to the test and rhino mocks which are located in another assembly. When…

Pouya Barrach-Yousefi
- 1,207
- 1
- 13
- 27
2
votes
2 answers
Why does my partial mock have all virtual methods mocked, even if no expectations are set?
I have a user control which does some validation in the ValidateChildren method which I would like to test. I have created a partial mock of the user control, but although I am not setting any expectations on the ValidateChildren method, I am…

Sam Holder
- 32,535
- 13
- 101
- 181
2
votes
1 answer
JMockit - Partial mocking and mocked parent
I would like to test (using JMockit) a class that looks like this:
class MyClass extends ComplexParentClass {
public void testedMethod() {
...
}
private int complexPrivateMethod() {
...
}
}
I can't change the…

davido
- 121
- 1
- 7
2
votes
1 answer
Not able to partial mock static method with PowerMockito
I am to mock a static function named toBeMockedFunction in Util class. This method is called from toBeUnitTested which is a public static void method. I want toBeMockedFunction to do nothing. I tried many approaches (snippet posted of such 2) of…

sandy
- 1,153
- 7
- 21
- 39
2
votes
0 answers
Getting "No last call on a mock available" error while trying to mock a private method using PowerMock
I am trying to mock a private method of a class.
I want to mock isBalancedTree method for the below class.
public class DummyClassForPowerMockTest {
public boolean isBalancedTree_1() {
System.out.println("Inside isBalancedTree_1");
…

Harshit Agrawal
- 903
- 1
- 7
- 11
2
votes
2 answers
Partial-mocking considered bad practice? (Mockito)
I'm unit-testing a business object using Mockito. The business object uses a DAO which normally gets data from a DB. To test the business object, I realized that it was easier to use a separate in-memory DAO (which keeps data in a HashMap) than to…

machinery
- 3,793
- 4
- 41
- 52
2
votes
1 answer
What is wrong with partial mocking in this case?
Let's say I have two methods, one of which is basically a wrapper for the other method with just a tiny bit of extra processing:
public class ItemRepositoryImpl implements ItemRepository {
...
@Override
public void delete(UUID itemID)…

Robyn P
- 644
- 9
- 8