Unit Testing in Development – Running Tests Across All Configurations and Platforms

cdevelopment-processnetunit testing

I have open source C# .NET project at GitHub with Appveyor CI + code coverage.

There are configurations like Release and Debug. There's also platforms like x86, x64 and Any CPU.

This results to following:

Configuration | Platform | Tests
--------------+----------+--------
Release       | x86      | 100/100
Release       | x64      | 100/100
Release       | Any CPU  | 100/100
Debug         | x86      | 100/100
Debug         | x64      | 100/100
Debug         | Any CPU  | 100/100

Should unit tests run always on all of the combinations (six) of these two dimensions when application is in development stage? ie. mainly only developers are in the process and lots of changes are taking place.

My intuition says that only Debug configuration and one platform should be tested.

My view is that Debug configuration gives more information and as C# being quite high level language and running in VM (CLR) there's no need to test x64 and x86 separately.

There's also third dimension with .NET framework version. And fourth with OS.

Is there best practises view in the field of what is or isn't necessary when application is being developed?

When shipping all tests are of course ran. Same with possible nightly/weekly/etc builds.

Best Answer

This has nothing to do with "a common view in the field" - this is all about what makes sense most.

Running unit tests (or any kind of automated tests) using only one configuration and only one platform is fine as long as the code under test as well as the test itself don't show any indications for behaving differently under different configurations and platforms (except for performance, of course).

In a ideal world, there is only one configuration required for running the tests. However, certain kind of code constructs or statements are more prone to behave differently in "Debug" and "Release", or differently in "x86" or "x64". There are obvious things

  • like explit tests #if DEBUG, and not so obvious things like

  • subtile differences in floating point precision.

To find out what applies to your case, the only sensible way is IMHO to gain experience with the code base in stake. This might be done by inspection, or by occasionally running the tests using a different configuration. And it will take some time, depending of the size of the code base. In a large code base, you will probably find out that there are some parts or components where testing with one configuration is not enough, and others (hopefully the bigger part) do not need more than configuration for testing.

If you ask which configuration you should prefer for unit testing, then it is IMHO obvious that

  • the configuration/platform used by the team in the code-compile-test-debug cycle needs to be the one for which you run the unit tests always

  • the configuration(s)/platforms used by your team for deployment should be tested before deployment, especially if you suspect they could behave differently.

You should also make sure everyone in the team is aware of the potential differences, and everyone who used some #if DEBUG statement is very carefully about not changing any behaviour which could become relevant for testing.