Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit testing application layers

I have a 3-tier application with Data access, service and presentation tiers. Where should i place the unit tests? On each layer? one presentation layer?

like image 433
joshua Avatar asked May 09 '26 06:05

joshua


1 Answers

Some of this depends on you're approach. If you've already got code in place, and you're putting unit tests in after the creation of the code - I'd start by adding some end to end acceptance tests. This will exercise all layers.

Then as you go in to make changes to any part of the system I'd start putting unit tests around the component being changed - first off just testing the existing functionality, then move onto adding unit tests for the new functionality. This works well if you're code is loosely coupled and split into well defined components. If not you're got a lot of work to do.

Depending on how thin your data access is, I would be less inclined to write any unit tests here as errors should be picked up quite cost effectively without having to unit test these.

If you're starting fresh, read up on BDD/TDD and use that approach to ensure quality.

like image 77
Tom Avatar answered May 10 '26 18:05

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!