Reputation: 3707
I want to write first unit test in my life.
At present, I am developing new ASP.NET MVC 5 project. This is simple workflow system. My project contains 4 layers:
I believe, that I need test Service layer firstly. Is that right? Which layer should I test first?
Upvotes: 3
Views: 63
Reputation: 10850
As per Mark Seemann's answer, you can test from UI layer first and finish with the data layer, or in reverse.
Who is responsible for the project? Which part of the project is business critical? Rather than test across each layer "horizontally", test through all of the layers for a particular piece of functionality "vertically".
This gives you the benefit of coverage based on business priorities and you can apply any testability changes you need to make or techniques across all of the layers as you start to test each piece of functionality.
Since you have written your code already, be prepared to refactor some code to make it more testable (for example setting up Dependency Injection to isolate code for unit testing) and make note of these changes to help design for testability in future.
Upvotes: 3
Reputation: 233150
There's no single correct approach, but the most common techniques are
As Code Complete describes, using dual approaches interchangeably can actually be beneficial, because the stuff you learn from doing one thing, helps you better understand what you need to do in the other end, and vice versa. I often do a bit of Outside-In, then some Bottom-Up, then some more Outside-In, etc.
Upvotes: 4