Skip to main content

All Questions

4 votes
3 answers
321 views

Clearing static state before testing each method

My SUT class depends on external static state (which generally should be avoided, I know). How do I make sure my tests do not depend on their order of execution? I mean other by introducing some reset(...
Sergey Zolotarev's user avatar
0 votes
0 answers
70 views

Is Spring Boot Unit Test Coverage with Integration tests only a bad practice?

I have recently come across a few codebases at work where the previous developers chose to reach the >80% coverage criteria by writing only integration tests with the @SpringBootTest annotation ...
Mary's user avatar
  • 1
0 votes
3 answers
434 views

Would you test this piece of configuration code? How do I determine which code is worth testing?

We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
LostInComputer's user avatar
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
1 vote
2 answers
532 views

How to avoid unit test duplication in wrapper classes?

Assuming I’ve a class with three methods, startCollection, add, endCollection. One test case is: if start was not called, add should return an error. I’ve mocked the persistency storing the state with ...
user avatar
0 votes
2 answers
104 views

How to cover by tests HTTP API wrapping library

As mentioned in title, I don't understand how I supposed to cover by tests code which is just wrap http api. I guess I can write only unit tests, because wrapped service is paid. Integration tests in ...
Eduard Romanyuk's user avatar
0 votes
1 answer
2k views

Java: Splitting a large unit test class

The project (Java/Spring) I currently work on has a rather large unit-test class for one of its services : more than 1000 lines, several Nested class (one per big functionality), some tests without a ...
Baerrow's user avatar
  • 125
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
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
0 votes
2 answers
387 views

Design Java Testing class for hierarchical objects

Consider the following POJO structure in my main code. I want to create some testing framework for this kind of hierarchical classes, where the calling test method can specify if they want to modify a ...
Novice User's user avatar
0 votes
2 answers
114 views

What to test when testing an API? [closed]

When testing an API (with, for example, Java), what parts should I actually be testing when calling methods of my Controller class (e.g. a Spring RestController)? For example, lets say I've got a ...
rezadru's user avatar
  • 21
-1 votes
1 answer
101 views

Understanding property based testing

I'm reading about property based testing and I'm wondering how can I test this my code using that paradigm. class Invoice { private final String id; private final String companyName; ...
Héctor Valls's user avatar
8 votes
3 answers
2k views

Philosophy on unit testing daisy-chained methods?

Problem Statement: I have a class that does some validation and it looks something like this: func a() {b()} func b() {c()} func c() {d()} func d() {e()} func e() {return} This is a simplified view, ...
John Lippson's user avatar
15 votes
5 answers
71k views

Unit testing a void method

In order to fix a bug in an application, I modified a method named postLogin by adding a call to an existing method named getShoppingCart. Code protected void postLogin() { getShoppingCart(); } ...
A_B's user avatar
  • 409
9 votes
1 answer
588 views

How to manage non-unit tests in a project?

I have some code in my project I personally call tests that are not unit tests. They are meant to be run and the result has to be evaluated by a human. I did this because I'm making a physics engine ...
Winter's user avatar
  • 705

15 30 50 per page