Skip to main content

All Questions

0 votes
1 answer
1k views

Mock a bean with 10 methods when I only use one?

I face some situations similar to the following simplified one: @Component class ServiceOne { @Autowired ServiceTwo two; void act() { ... two.a(); ... } } @...
ch271828n's user avatar
  • 181
0 votes
2 answers
238 views

Is there any benefit testing only with mocks/fakes/doubles?

Say I want to test the behavior of the GUI while I follow a PassiveView approach. I also use the command pattern to handle the actions of the user. So given a PersonView and a PersonService with a ...
George Z.'s user avatar
  • 705
6 votes
1 answer
16k views

Should I mock ObjectMapper in my unit tests?

I have different services in a spring application that have a dependency on Jackson ObjectMapper, the unit tests rely on @InjectMocks to inject all the various dependencies to the class that is under ...
Pampa Nello's user avatar
0 votes
1 answer
85 views

Should all third party methods that access outside resources (like other databases) be wrapped up?

From the perspective of unit testing, the code under test should obviously not be accessing outside resources so the third party methods need to be mocked. However, it seems like this is poor practice ...
JobHunter69's user avatar
3 votes
4 answers
1k views

How do I deal with the fact that I am forced to make helper functions public for testing purposes?

I've encountered several scenarios that require me to mock certain helper methods because they call outside resources. As a result, I'm forced to convert all my helper methods from private into public....
JobHunter69's user avatar
6 votes
3 answers
7k views

What is recommended way to create test data for unit test cases?

I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a core part of our application and there are number of scenarios in it, I want to write ...
Bhushan's user avatar
  • 215
1 vote
1 answer
130 views

Mocked dependencies verification - Best practices

I have a simple question about best practices in unit test verifications. Given this example: @Test public void methodUnderTest() { when(mockedDependency.someMethod()).thenReturn(someValue); ...
Bronx's user avatar
  • 127
2 votes
2 answers
4k views

Testing using mocking, must I mock all dependencies too?

I have the following method to test: public List<MarkId> getMarkIdList(ICar carDoc) { ICourseCar courseCarDoc = courseCarRep.get(carDoc); List<MarkWag> markWagList = ...
user1883212's user avatar
3 votes
1 answer
12k views

Should I use a mock or create a new instance of an object in unit tests? [closed]

I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and a ...
Ales's user avatar
  • 39
3 votes
2 answers
5k views

Converting static utility class into singleton

In company where I work we have lots of "utility" classes, each has lots of code inside (thousands of lines), and they are all static. And one static methods call anothers. The problem here is that ...
maxpovver's user avatar
  • 131
4 votes
2 answers
886 views

Domain object model: query by id vs object

Let assume I have two simple model classes: Product and Brand It is obvious I have a query method in Product class like this Product product = Product.findById(123); What if, I want to query ...
Yoga's user avatar
  • 325
5 votes
3 answers
2k views

how and should I 'unit test' an entire package?

I'm still learning to be good about doing unit level testing, as I've always been a little sloppy about only doing functional testing in the past, so I want to double check I'm doing this 'right'. I ...
dsollen's user avatar
  • 1,153
0 votes
1 answer
1k views

Method visibility for testing partial mocks

I'm currently writing unit tests to test behavior of a method and would like to partially mock the methods calling injected properties. For example: public void doSomething() { int complicatedInt =...
dardo's user avatar
  • 355
11 votes
3 answers
8k views

Mocking concrete class - Not recommended

I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended. Here some sample code of a unit-test for the ...
Mik378's user avatar
  • 3,916
7 votes
7 answers
3k views

Is mocking for unit testing appropriate in this scenario?

I have written around 20 methods in Java and all of them call some web services. None of these web services are available yet. To carry on with the server side coding, I hard-coded the results that ...
Vinoth Kumar C M's user avatar

15 30 50 per page