简体   繁体   English

网络服务和nunit测试

[英]web service and nunit testing

I have created a console application that calls a method on a webservice. 我创建了一个调用webservice上的方法的控制台应用程序。 I have accessed the webservice and get the response back from the console application that I expect. 我已经访问了webservice并从我期望的控制台应用程序中获取响应。 When I create a separate test assembly and create some nunit tests which call the same method in the same way i get the following exception:- 当我创建一个单独的测试程序集并创建一些nunit测试时,它们以相同的方式调用相同的方法,我得到以下异常: -

System.InvalidOperationException: Could not find default endpoint element that references contract 'xxxxx.xxx' in the ServiceModel client configuration section. System.InvalidOperationException:无法在ServiceModel客户端配置部分中找到引用合同“xxxxx.xxx”的默认端点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

Anyone experienced this before? 以前有人经历过吗?

Yes, make sure you add an app.config file to the unit test project and add the same settings you have in the console application's config file to it. 是的,确保将app.config文件添加到单元测试项目中,并将控制台应用程序配置文件中的相同设置添加到单元测试项目中。

Good luck! 祝好运!

I had the same issue, however when opening the test project .NET dll directly in NUnit, the test(s) would succeed, but if I then saved the test as a project in NUnit, it would then go back to the above error! 我遇到了同样的问题,但是当在NUnit中直接打开测试项目.NET dll时,测试会成功,但如果我将测试保存为NUnit中的项目,那么它将回到上面的错误!

The fix for me was to save the test as an NUnit project, then select from the menu 'Project=>Edit...' and at the bottom select the 'General' tab and in the field 'Configuration File Name:' enter the full name of the GENERATED 'app.Config' file in the '\\Debug' folder so [dllname].config. 对我来说,修复是将测试保存为NUnit项目,然后从菜单“Project => Edit ...”中选择,在底部选择“常规”选项卡,在“配置文件名:”字段中输入'\\ Debug'文件夹中GENERATED'app.Config'文件的全名,所以[dllname] .config。

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

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