Write Unit tests into an assembly or in a separate assembly?

后端 未结 5 795
轮回少年
轮回少年 2020-12-16 13:08

When writing unit tests, do you place your tests inside the assembly you wish to test or in a separate test assembly? I have written an application with the tests in classes

5条回答
  •  盖世英雄少女心
    2020-12-16 13:21

    I'd say that the only time you want to incorporate any test code in your final deployment is when the test code is there for monitoring and control of the application.

    Leaving the test code in the deployment:

    • bloats the code to no real advantage at all - all that extra code tagging along that isn't going to be used at all in situ.
    • affects releases - do you release a new version of the complete app. when what you've improved is only in the test code, e.g. a test suite is extended as a result of a bug fix.
    • you can't easily reuse the test framework on another project - if you are always releasing app's that are clogged with test code, any subsequent projects have to reuse the same test code. Otherwise, you finish up with the situation where app A is using v1.2 of the test platform for those aspects of the app. that are common across all your app's, e.g. a presentation layer, or a business logic framework, etc. And app. B is using v1.1 of the test framework, app. C is using v1.2.1, etc.

    Decoupling on the otherhand allows you to:

    • easily upgrade and extend the test suite as required.
    • easily reuse the test suite across multiple projects.
    • use a common test framework across multiple projects.

    HTH

    cheers,

    Rob

提交回复
热议问题