Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit tests in production release code? [closed]

Couple of questions:

1.) Do you unit test release code?

2.) If so, do you then leave those unit tests intact so that the tests themselves exist in the production environment?

I see the value in #1, but is it a "good practice" to create dependencies in production to, for example, the NUnit assemblies?

Give me your thoughts.

like image 764
Scott Marlowe Avatar asked Aug 14 '09 16:08

Scott Marlowe


People also ask

Do unit tests run in production?

Unit tests run on all build configurations. Unit tests are always intact but this does not mean that shipped assemblies are dependent on anything relating to the tests. Tests are always written in a parallel assembly (in the same build environment) that then tests the production assembly.

Should unit tests be written before code?

According to that line of reasoning, writing unit tests before writing code is a recommended way to do proper software engineering.

Is code coverage should happen after unit testing?

Code coverage is calculated for a file based on the unit tests that SUCCESSFULLY passed. After all the unit tests are run you are able to see either in your browser the exact lines in your code that are being executed or right in your terminal.

When should unit tests be executed?

Unit testing is the first software testing phase in SDLC and it is usually taken up during the development of the application. These unit test cases are written and executed by software developers.


2 Answers

  1. Absolutely. If our build passes the unit test suite then it's tagged and a candidate for production
  2. No. Deployments don't include tests nor the supporting libraries (e.g. unit test libraries, mocking etc.)

The above is my general rule (I'm usually deploying to non-technical users). However I do have an exception, which is a programming utility that is unit tested with ~130 test scripts. Because the test scripts double as examples, I deploy those along with the production release, and consequently they enhance the existing documentation.

Deploying tests with open-source code is definitely worthwhile. It allows people to play with, modify and submit patches, whilst being able to run the tests that passed successfully to permit the original artifact to be released.

like image 183
Brian Agnew Avatar answered Sep 19 '22 05:09

Brian Agnew


Yes and Yes, application behaviour can be different between release and debug builds, hence as part of the release process the release build has to pass all its unit tests.

like image 20
Bob Avatar answered Sep 21 '22 05:09

Bob