简体   繁体   English

使用一个变量执行NUnit测试用例

[英]Executing NUnit test cases with one variable

I have a number of Selenium tests written in C# that are being compiled to a .dll which is being run from the command line using nunit-console.exe. 我有许多用C#编写的Selenium测试,它们被编译为.dll,它是使用nunit-console.exe从命令行运行的。

These tests are working fine for the moment in my testing environment consisting of one site, but I need for the tests to be more general purpose... 这些测试目前在我的测试环境中正常工作,包括一个站点,但我需要测试更通用...

The idea behind these tests is that they will be used after a piece of software has been deployed. 这些测试背后的想法是,它们将在部署一个软件之后使用。 The software being deployed will set up a site in IIS, and this site will bind to a port that will be automatically assigned based on what is available at the time. 正在部署的软件将在IIS中设置一个站点,该站点将绑定到一个端口,该端口将根据当时可用的内容自动分配。 I need for my tests to know which port the website will be running on, otherwise it might be testing the wrong site. 我需要测试才能知道网站将运行哪个端口,否则可能会测试错误的网站。 I am able to identify the port that it is running on by using a return value from the deployment tools I am using. 我能够通过使用我正在使用的部署工具的返回值来识别它正在运行的端口。

My question therefore is: Is it possible to pass an argument (website port number for example) to nunit-console that can be used by my already compiled Selenium tests? 因此我的问题是:是否可以将一个参数(例如网站端口号)传递给我已编译的Selenium测试可以使用的nunit-console?

The only other solution that I can think of is to build the tests after deployment. 我能想到的唯一其他解决方案是在部署后构建测试。 I would like to avoid this as the software has already gone through the build phase, and building again seems messy to me especially if our build server (Bamboo) loses visibility of the building process due to it being some custom script within a deployment task. 我想避免这种情况,因为软件已经经历了构建阶段,并且再次构建对我来说似乎很麻烦,特别是如果我们的构建服务器(Bamboo)由于它是部署任务中的某些自定义脚本而失去对构建过程的可见性。

Thanks in advance. 提前致谢。

You can use an environment variable. 您可以使用环境变量。

In your selenium test you can read it with 在您的硒测试中,您可以阅读它

var port = System.Environment.GetEnvironmentVariable("SITE_PORT");

and you can set it from different sources, for example batch script or prompt: 您可以从不同的来源设置它,例如批处理脚本或提示:

set SITE_PORT=<result of command>

AFAIK there is no way to do that in current version of NUnit. AFAIK在当前版本的NUnit中无法做到这一点。 One of possible solutions in your case can be using configuration file (which I sometimes use). 在您的情况下可能的解决方案之一可以使用配置文件(我有时使用)。 If you know on which port your tests is running you can save that info into config file and get data from it (using ConfigurationManager): url or wathether you need. 如果您知道测试运行的端口,您可以将该信息保存到配置文件中并从中获取数据(使用ConfigurationManager):url或者您需要它们。 YOu'll not spend too much time on changing your tests (you almost don't need to to that, just add method which get url from config file and paste it in correct place =)). 你不会花太多时间来改变你的测试(你几乎不需要这样做,只需添加从配置文件获取url的方法并将其粘贴到正确的位置=))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM