Where to write unit test code?

I thought this would be a common question, so I searched for a while, but could not find it.

I'm going to start a new project (C #,. Net 3.5), and I was thinking about where I should write unit test code. I can create a unit test project and write all the code there, or I can write unit test code with the class itself.

What do you recommend and why? What should be considered before choosing an approach (reservations?)

EDIT: About writing a modular test code with "test code": Removing test code from a production assembly is not difficult. What is conditional compilation for? Correctly?

Just throwing this point because the answers reject the second option only because the production assemblies will be bold.

+5
source share
4 answers

A separate project, the same solution. Use InternalsVisibleToif you want to access the internals from the test code.

Separating the test from the production code:

  • makes it more obvious that what
  • means you don’t need dependencies on the test frameworks in your production project.
  • keeps your deployed code more compact
  • Avoids including test data files in the deployment assembly.

Saving code in the same solution:

  • speeds up the testing cycle
  • simplifies the transition between production and test code.
+19
source

, TestFixtures. ( - ) .
, ( ).

, , InternalsVisibleTo. , , , .

+3

- unit test . . , , DLL , , , .

, , .

+2

.

, SUT (System in Test) , unittests . , , .

, . , .

, " " . ... IMHO...

Edit:

:

: " ": . . ?

, "" , , , , , , , . , 100% ? , , ;)

+2
source

All Articles