我应该在同一个项目中混合我的UnitTests和我的Integration测试吗?

时间:2023-01-13 23:43:46

I am using NUnit to test my C# code and have so far been keeping unit tests (fast running ones) and integration tests (longer running) separate, and in separate project files. I use NUnit for doing both the unit tests and the integration tests. I just noticed the category attribute that NUnit provides, so that tests can be categorized. This begs the question, should I mix them together and simply use the category attribute to distinguish between them?

我正在使用NUnit来测试我的C#代码,并且到目前为止一直保持单元测试(快速运行的)和集成测试(运行时间更长),以及单独的项目文件。我使用NUnit进行单元测试和集成测试。我刚刚注意到NUnit提供的category属性,因此可以对测试进行分类。这引出了一个问题,我应该将它们混合在一起并简单地使用category属性来区分它们吗?

6 个解决方案

#1


7  

if it is not too difficult to separate them, do so now

如果将它们分开并不太难,现在就这样做

unit tests should be run early and often (e.g. every time you change something, before check-in, after check-in), and should complete in a short time-span.

单元测试应该尽早并经常运行(例如,每次更改时,在办理登机手续,办理登机手续后),并且应在短时间内完成。

integration tests should be run periodically (daily, for example) but may take significant time and resources to complete

集成测试应定期运行(例如每天),但可能需要大量时间和资源才能完成

therefore it is best to keep them separate

因此最好将它们分开

#2


1  

I find that using separate projects for unit test and integration tests tends to create a little too many top level artifacts in the projects. Even though we're TDD and all, I still think the code being developed should be deserving at least half of the top-level of my project structure.

我发现使用单独的项目进行单元测试和集成测试往往会在项目中创建一些太多的*工件。尽管我们都是TDD,但我仍然认为正在开发的代码至少应该是我项目结构顶层的一半。

#3


1  

seperate them if possible, because integration tests normally take much longer than UnitTests. Maybe your project grows and you end up with very much tests, all which take a short amount of time - except the integration tests - and you want to run your UnitTests as often as possible...

如果可能的话,将它们分开,因为集成测试通常比UnitTests花费更长的时间。也许你的项目增长了,你最终得到了很多测试,所有这些都需要很短的时间 - 除了集成测试 - 你想尽可能多地运行你的UnitTests ...

#4


0  

I don't think it really matters that much but separating them sounds like a better idea, since isolation, automation will be so easier. And category feature is nice but not that good from usability point of view.

我不认为它真的那么重要,但将它们分开听起来更好,因为隔离,自动化将变得如此简单。从可用性的角度来看,类别功能很不错但不是很好。

#5


0  

The original motivation behind [Category] was to solve the problem you mention. It was also intended to create broader test suites but that is kind of what you are doing.

[类别]背后的原始动机是解决你提到的问题。它还打算创建更广泛的测试套件,但这就是你正在做的事情。

Do be careful with [Category]. Not all test runners support it the same way the NUnit gui does (or did, I haven't upgraded in a while). In the past some runners would ignore the attribute if it was on the class itself or just ignore it all together. Most seem to work now.

请注意[类别]。并非所有测试跑步者都支持它,就像NUnit gui一样(或者我没有在一段时间内升级)。在过去,一些跑步者会忽略该属性,如果它属于类本身或者只是忽略它们。大多数似乎现在都在工作。

#6


0  

I would keep with whatever method you're currently using. It's more of an opinion thing, and you wouldn't want to have to re-tool your whole testing method.

我会保留你目前正在使用的任何方法。这更像是一种观点,你不希望重新使用整个测试方法。

#1


7  

if it is not too difficult to separate them, do so now

如果将它们分开并不太难,现在就这样做

unit tests should be run early and often (e.g. every time you change something, before check-in, after check-in), and should complete in a short time-span.

单元测试应该尽早并经常运行(例如,每次更改时,在办理登机手续,办理登机手续后),并且应在短时间内完成。

integration tests should be run periodically (daily, for example) but may take significant time and resources to complete

集成测试应定期运行(例如每天),但可能需要大量时间和资源才能完成

therefore it is best to keep them separate

因此最好将它们分开

#2


1  

I find that using separate projects for unit test and integration tests tends to create a little too many top level artifacts in the projects. Even though we're TDD and all, I still think the code being developed should be deserving at least half of the top-level of my project structure.

我发现使用单独的项目进行单元测试和集成测试往往会在项目中创建一些太多的*工件。尽管我们都是TDD,但我仍然认为正在开发的代码至少应该是我项目结构顶层的一半。

#3


1  

seperate them if possible, because integration tests normally take much longer than UnitTests. Maybe your project grows and you end up with very much tests, all which take a short amount of time - except the integration tests - and you want to run your UnitTests as often as possible...

如果可能的话,将它们分开,因为集成测试通常比UnitTests花费更长的时间。也许你的项目增长了,你最终得到了很多测试,所有这些都需要很短的时间 - 除了集成测试 - 你想尽可能多地运行你的UnitTests ...

#4


0  

I don't think it really matters that much but separating them sounds like a better idea, since isolation, automation will be so easier. And category feature is nice but not that good from usability point of view.

我不认为它真的那么重要,但将它们分开听起来更好,因为隔离,自动化将变得如此简单。从可用性的角度来看,类别功能很不错但不是很好。

#5


0  

The original motivation behind [Category] was to solve the problem you mention. It was also intended to create broader test suites but that is kind of what you are doing.

[类别]背后的原始动机是解决你提到的问题。它还打算创建更广泛的测试套件,但这就是你正在做的事情。

Do be careful with [Category]. Not all test runners support it the same way the NUnit gui does (or did, I haven't upgraded in a while). In the past some runners would ignore the attribute if it was on the class itself or just ignore it all together. Most seem to work now.

请注意[类别]。并非所有测试跑步者都支持它,就像NUnit gui一样(或者我没有在一段时间内升级)。在过去,一些跑步者会忽略该属性,如果它属于类本身或者只是忽略它们。大多数似乎现在都在工作。

#6


0  

I would keep with whatever method you're currently using. It's more of an opinion thing, and you wouldn't want to have to re-tool your whole testing method.

我会保留你目前正在使用的任何方法。这更像是一种观点,你不希望重新使用整个测试方法。