是否合理/可能使用Nunit的配置来改变测试行为?

时间:2022-05-04 07:46:55

I've got a suite of about 20 tests that I run on my Development server. I'd like an easy way to switch over to the Alpha server and run those same 20 tests. But I don't want to run them on all servers every time. Typically I'd run the tests on Dev until they are all green, then roll code to Alpha, run tests, etc. Many iterations on Dev, a few on Alpha, then in theory one run on every server up the stack to Release.

我在开发服务器上运行了大约20个测试套件。我想要一种简单的方法切换到Alpha服务器并运行相同的20个测试。但我不想每次都在所有服务器上运行它们。通常我会在Dev上运行测试,直到它们全部变为绿色,然后将代码转换为Alpha,运行测试等。在Dev上进行许多迭代,在Alpha上进行一些迭代,然后理论上在堆栈上的每个服务器上运行到Release。

The way this is accomplished now is with a variable in the TestFixture. That's all fine -- but requires a rebuild every time I want to change environments. But I saw a menu for Configurations and I thought this would be nifty to use. Add a configuration for each environment, point to that configuration, run tests and they run on the correct server. There's some smelly hardcoding in there: assuming that the name of the environment would have to match up with the name of the target test environment. I can live with that.

现在实现的方法是使用TestFixture中的变量。这一切都很好 - 但每次我想要改变环境时都需要重建。但是我看到了Configurations的一个菜单,我认为使用它会很有用。为每个环境添加配置,指向该配置,运行测试并在正确的服务器上运行。那里有一些臭硬编码:假设环境的名称必须与目标测试环境的名称相匹配。我可以忍受这一点。

First question: is there a better way to do this? Second question: is this even possible? I'm not able to find a way to read those Configurations at the TestFixture level.

第一个问题:有更好的方法吗?第二个问题:这甚至可能吗?我无法找到在TestFixture级别读取这些配置的方法。

1 个解决方案

#1


Just use standard .NET configuration files. Appsettings or configuration elements. Any dll (including test) can read them. E.g. mytest.dll.config for mytest.dll, We do this for our "component" or "integration" tests, that have some external dependency, such as a sql server. Test has to know where the server is.

只需使用标准的.NET配置文件。 Appsettings或配置元素。任何dll(包括测试)都可以读取它们。例如。 mytest.dll的mytest.dll.config,我们为“组件”或“集成”测试执行此操作,这些测试具有一些外部依赖性,例如sql server。测试必须知道服务器的位置。

Requisite note on unit tests: be aware you are talking about acceptance or integration tests. Valuable, but expensive to maintain and slow. You should have very few of those, and should have many more unit tests (which would not care where the server is).

关于单元测试的必要注意事项:请注意您正在讨论验收或集成测试。有价值,但维护和缓慢昂贵。你应该只有很少的那些,并且应该有更多的单元测试(不关心服务器在哪里)。

#1


Just use standard .NET configuration files. Appsettings or configuration elements. Any dll (including test) can read them. E.g. mytest.dll.config for mytest.dll, We do this for our "component" or "integration" tests, that have some external dependency, such as a sql server. Test has to know where the server is.

只需使用标准的.NET配置文件。 Appsettings或配置元素。任何dll(包括测试)都可以读取它们。例如。 mytest.dll的mytest.dll.config,我们为“组件”或“集成”测试执行此操作,这些测试具有一些外部依赖性,例如sql server。测试必须知道服务器的位置。

Requisite note on unit tests: be aware you are talking about acceptance or integration tests. Valuable, but expensive to maintain and slow. You should have very few of those, and should have many more unit tests (which would not care where the server is).

关于单元测试的必要注意事项:请注意您正在讨论验收或集成测试。有价值,但维护和缓慢昂贵。你应该只有很少的那些,并且应该有更多的单元测试(不关心服务器在哪里)。