All Questions
16 questions
11votes
3answers
8kviews
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 ...
8votes
3answers
5kviews
What should I mock in tests of an application with service tier and DAO tier?
My classes are following this structure Service Tier (creates and maps InputDTO to DB Data) DAO Tier (actually executes DB calls) When I write service tier JUnit tests, the DAO tier is called, and ...
7votes
7answers
3kviews
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 ...
6votes
3answers
7kviews
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 ...
6votes
1answer
16kviews
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 ...
5votes
3answers
2kviews
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 ...
4votes
2answers
886views
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 ...
3votes
4answers
1kviews
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....
3votes
2answers
5kviews
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 ...
3votes
1answer
12kviews
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 ...
2votes
2answers
4kviews
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 = ...
1vote
1answer
130views
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); ...
0votes
2answers
238views
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 ...
0votes
1answer
1kviews
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(); ... } } @...
0votes
1answer
85views
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 ...