Do you put unit tests in same project or another project?

后端 未结 15 1643
失恋的感觉
失恋的感觉 2020-12-02 05:23

Do you put unit tests in the same project for convenience or do you put them in a separate assembly?

If you put them in a separate assembly like we do, we end up wit

15条回答
  •  失恋的感觉
    2020-12-02 06:17

    If NUnit framework is used, there is an additional reason to put the tests in the same project. Consider the following example of the production code mixed with unit tests:

    public static class Ext
    {
         [TestCase(1.1, Result = 1)]
         [TestCase(0.9, Result = 1)]
         public static int ToRoundedInt(this double d)
         {
             return (int) Math.Round(d);
         }
    }
    

    The unit tests here serve as documentation and specification to the code being tested. I do not know how to achieve this effect of self-documenting, with the tests located in a separate project. The user of the function would have to search for the tests to see those test cases, which is unlikely.

    Update: I know that such usage of TestCase attribute was not that the developers of NUnit intented, but why not?

提交回复
热议问题