Linked Questions

2
votes
2answers
8k views

How to unit test static void methods? [duplicate]

How does one go about unit testing static void methods? I have a few more questions: Is it necessary to unit test database queries like insert, select and update queries ? If so, how does one test ...
12
votes
1answer
5k views

Are we abusing static methods?

A couple of months ago I started working in a new project, and when going through the code it stroke me the amount of static methods used. Not only utility methods as collectionToCsvString(Collection&...
8
votes
5answers
387 views

Should methods that are not “pure functions” and that interact with external APIs or hardware be static?

When reading about when to make a method static or not, I've seen a general principle, as summarized by this post, that a method should only be static if it does not modify a state and its result ...
14
votes
7answers
2k views

Is it a code smell if you are frequently creating an object just to call a method on it

I inherited a code base where there is a lot of code that goes something like this: SomeDataAdapter sda = new SomeDataAdapter(); sda.UpdateData(DataTable updateData); And then sda is never used ...
6
votes
2answers
2k views

Java: Is it okay to abuse Spring beans (@Component) rather than use static final utility classes?

I'm torn between using DI and static utility classes on my code. I currently created a DateUtil static class that is only meant to be accessed statically. This class is responsible for just creating ...
9
votes
1answer
946 views

How does functional style helps with mocking dependencies?

From the interview with Kent Beck in a recent Java Magazine issue: Binstock: Let’s discuss microservices. It seems to me that test-first on microservices would become complicated in the sense that ...
6
votes
2answers
574 views

Static services and testability

Where is the figurative line drawn for using static services in a project? I am a coop student working and learning how to write .net MVC projects. I've been developing trying to stick to TDD. In my ...
0
votes
2answers
2k views

Static methods and testability

I have an application service which returns entity by its registration number public Entity FindByRegNumber(string number) { if (!RegNumber.IsValid(number)) { return null; } ...
1
vote
4answers
366 views

Is there a good way to communicate the intent that a class only contains referentially transparent methods?

My workplace mostly uses C# for writing code. I'm trying to figure out a good way to indicate that a class with referentially transparent methods is intended to be referentially transparent (i.e., ...
3
votes
1answer
181 views

Dependencies between functions-only modules: hardcoding vs alternatives

In switching from a procedural background to "FP in the small, OO in the large" I'm grappling with the following problem. Suppose there're modules, each only containing numerical math functions ...