For quick experiments, I prefer to use "unit tests" –i.e. annotating one (or more) method with [TestMethod]
– over creating a tiny project with a Main
method.
A test method has some advantages over a tiny project:
- it is quicker to write a method and annotate it with
[TestMethod]
than to create a new project; - the test method can use facilities provides by the visual studio test tools such as test fixtures shared with similar experiments (via
[TestInitialize]
); - the method can be executed by right clicking and selecting "Run test" (in visual studio 2015); and,
- using
Assert()
instead of inspecting a value via the debugger or viaConsole.WriteLine()
automatically documents the intent and the results of the experiment and makes it repeatable without manual intervention.
A problem is that these experiments show up in the visual studio test explorer, this causes clutter and makes it difficult to distinguish real unit tests from experiments. (I'm not using any other testing reporting tools, CI, etc., but I assume that the problem would occur there as well.)
Is there a way to have the advantages of using [TestMethod]
for experiments and avoid the clutter that it causes at the same time?
I tried the following to solve this problem:
-
Have the
[TestClass]
and the[TestMethod]
attributes as comments and uncomment them when you want to run the experiment.This is what I currently do. It works, but running an experiment is somewhat cumbersome.
-
Use
[Ignore]
attribute.Clutters the test explorer view with ignored tests and requires commenting out the
[Ignore]
attribute to run the test.
TL;DR
How to write experiments (using visual studio unit tests) without the experiments cluttering the reports about real unit tests?
Aucun commentaire:
Enregistrer un commentaire