如何在NUnit中运行此测试

问题描述:

为什么在我写NUnit时: Assert.AreEqual(ConfigurationManager.ConnectionStrings [“FertigungRead”] .ConnectionString,“Data Source = server511; Initial Catalog = FERTIGUNG; Persist Security Info = True” );如何在NUnit中运行此测试

它不运行测试并引发错误:未将对象引用设置为对象的实例。

但ConfigurationManager是静态类。那么我该如何运行这个测试呢?

+0

检查我的答案你的其他问题之一http://stackoverflow.com/questions/2409208/the-problem-with-nunit-and-app-config/5821977#5821977 – skyfoot 2011-05-04 17:12:16

运行测试 - 但测试失败,因为ConfigurationManager.ConnectionStrings["FertigungRead"]返回null。 请参阅this post about app.config files an NUnit,因为这是从哪里获取配置。

但是,我真的没有看到配置文件值的测试作为有价值的单元测试...是更合理测试的一部分吗?

+0

是的,它是更合理的一部分测试,但错误是在ConfigurationManager的部分,所以我只提到它。 – Mike 2010-03-05 10:17:22

+0

,我复制了app.config文件到我正在运行测试的项目中,并且包含nunit.framework引用,但它仍然不起作用 – Mike 2010-03-05 10:22:20