The value of integration tests + tools to make them easier to write

Legacy apps are sometimes defined as “software solutions that do not have unit tests”.

Without the capability to unit test a business software, developers can’t reliably predict how the software solution will behave under different scenarios.

Migrating a legacy solution into a more modern application is no easy task.
Typically this involves the following steps:

  • Adding dependency injection (DI) to the solution
  • Breaking up tight dependencies between classes by adding interfaces and using DI to inject concrete implementations of any dependent classes at runtime to the classes that need them
  • Replace the use of static classes with classes that expose an interface and are also injected at runtime using our DI container
  • Break up complex classes into simpler classes that follow the Single Responsibility principle

Migrating to decoupled apps

When we accomplish the steps outlined above, our legacy application will be more like a modern app –

– but making all of these changes can introduce errors into a stable legacy app.

Here are some tools that you may find useful when you are adding integration tests into a legacy solution.

NMemory ( https://github.com/tamasflamich/nmemory )

NMemory is a lightweight non-persistent in-memory relational database engine that is purely written in C# and can be hosted by .NET applications

This may help when testing business logic that requires a database. It will require some refactoring in order to use it as your data layer needs to access this database instead of the Entity Framework or ADO.NET calls.

Effort ( https://effort.codeplex.com/ )

This is available as a nugget package. It allows you to create automated tests for Entity Framework based applications. It is a data provider that uses an in-process memory database (NMemory) instead of the traditional SQL database.

This will also allow you to create instances of a memory database and populate the current state of the database from a series of CSV files. This makes it easy to test complex scenarios that may require a complex database setup in order to be tested properly.

Source code: https://github.com/tamasflamich/effort

You can learn more about it here:
https://tflamichblog.wordpress.com/2012/07/31/using-effort-in-complex-applications/

AutoFixture ( https://github.com/AutoFixture/AutoFixture )

This is a library designed to minimize the steps necessary to accomplish the “Arrange” phase of a test. It makes it easy to create object graphs containing test data.

This makes it easy to create an instance of a complex object that you may need to pass into a method that you are testing. This tool will create an instance of the complex object and populate it with random data. You can simply provide the values for the properties that you need in order for your specific test to execute successfully.

Faker ( https://github.com/slashdotdash/faker-cs )

This project makes it easy to create fake data that more closely resembles real business data. It can be used to populate a test, to seed a new database in order to allow for more realistic load testing or to be able to show how the UI operates under the expected load of a full database.

You can learn more about it here:
http://10consulting.com/2011/11/18/populating-test-data-using-c-sharp/

—-

I hope these tools help you in trying to improve your existing app by making it easier to create and manage your integration tests.

Leave a Reply

Skip to toolbar