Unit Testing – Write Unit Tests for Libraries or Just the Application?

Architecturecunit testingvalidationvisual studio

Background

I am fairly new to unit testing, and have been recently using the Visual Studio Test Manager to create my Unit Tests. The way that I have currently been doing things is as follows:

  1. Create some libraries.
  2. Add the libraries to one big solution, along with the application.
  3. Create a folder called Tests that I put my Tests project into.
  4. Write unit tests for my libraries and stuff them all into the same folder called "Tests".

I run all of my tests, and this method seems to work for me. The reason I do it this way is that I sometimes feel I cannot create any practical tests unless all of the classes necessary for the application are actually present/involved in my solution.

Question

Should I be creating tests as I create the libraries?

I don't see the practicality, and it seems to just create more overhead getting the work done because I would have to create tests again for my application anyway.

Best Answer

You should be creating tests for all the code that you write, regardless of whether they're libraries or your application. Why ?

  1. you can assert that the code you write works
  2. the tests assert that that code continues to work as you change or add subsequent code.

In short, it doesn't matter whether it's a library or an application that you're writing code for.

Related Topic