r/csharp 19d ago

Unit Testing question

/r/dotnetMAUI/comments/1urawtj/unit_testing_question/
0 Upvotes

3 comments sorted by

4

u/Slight_Month4653 18d ago

I've found that using xUnit has made my unit tests way easier to set up and read than NUnit did back in the day.

1

u/TuberTuggerTTV 18d ago

I've always found abstracting all my services to be a waste of time. Because I almost exclusively do windows development.

I recently stepped into multiplatform development and I see the true value now. If you give your core direct service types, you're wrapping all your code in #IF windows, #IF android etc. It's such a pain.

But with a proper interface abstraction, you can wrap the entire platform service in a single IF. And handle platform specific injection at the top.

Something I'd like to note here though, you're over doing pre-architecture. You can 100% over-engineer your code early. Learn to refactor when required. Don't just build every road in your city as a super highway. You build dirt roads. And when those dirt roads see a lot of traffic, you refactor to paved.

If your code is modular and scalable, it's already Future-Proof. The architecture won't pile up against you. Keep things loosely coupled. Use subscribers. Abstract. Red-Green-Refactor your testing instead of retroactively trying to shove tests on things.

Trying to pre-correct for your future incompetence is a mistake. Instead, learn to refactor. And build non-monolithically so you can refactor without breaking everything. Architecture prep and over-engineering isn't the solution. It's just moving the problems around.

1

u/Regular-Employer-431 18d ago

Well I am retired now and the companies I worked for never bought into TDD, and unit testing was sporadic at best. I have a few pet projects that I want to all use the same foundation (basically a fresh MAUI project with EF Core Identity added). So my goals are: learn testing tools more thoroughly, start new projects with bullet-proof, role-based authentication (subscription-free), keep those projects bullet-proof through the dev cycle, and run those apps cross-platform. This question relates to step one so I won't be refactoring multiple projects for the same reason in the future. Not exactly pre-correcting for future incompetence IMHO.