Using C# Named Arguments to Declutter Complex Tests

Using C# Named Arguments to Declutter Complex Tests

I've got a quick tip this week, about tests and a cool feature of C#.

I've got a quick tip this week, about tests and a cool feature of C#.

For better or for worse, my team and I often build projects that are large, complex beasts. In all of them, we prefer to use Dependency Injection as a way to construct complex objects.

A simple example of this might be that a given C## class UserService needs a dependency on UserRepository, and so we would write the UserService class like this:

The real world is never that simple, though.

No matter what architecture we use, what patterns we follow, or how diligent we are with separation of concerns, sometimes we still end up with complex classes that require a bunch of dependencies:

At a certain point, trying to refactor this down any further produces no viable way to do so, and we are forced to leave it in its complex, seemingly-too-large state.

This gets more annoying once we start writing tests for any given complex class. Sometimes the method being tested would only require one custom mock, and the other dependencies for the tested class could remain being the default mocks.

c# tips testing

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

top 30 Python Tips and Tricks for Beginners

In this post, we'll learn top 30 Python Tips and Tricks for Beginners

Software Testing 101: Regression Tests, Unit Tests, Integration Tests

How do scientists demonstrate that a drug or vaccine is effective? Putting it to the test. It's your only choice. And, if you're reasonable, you'd never use medications that haven't been thoroughly tested. So, why don't you test software as thoroughly as you should?

Let's Give Some Unit Testing Love to C# 8 and C# 9 Features

How to use C#9 and C#8 features in JustMock unit tests

Dicey Issues in C/C++

C/C++ problems. If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends.

C# Performance tips and tricks

Improving C# performance feels like a losing battle? Don't worry. Put in practice the tips in this post and start to see tangible gains.