简体   繁体   English

NUnit在.Net 4.0动态关键字下未通过测试

[英]NUnit is not failing test with dynamic keyword of .Net 4.0

I am using NUnit with Visual Studio Express Edition 2010 for C#, Now, normally test works fine. 我正在将NUnit与Visual Studio Express Edition 2010 for C#一起使用,现在,通常可以正常进行测试。 But whenever I try to use Massive.cs, which is open source api to access database. 但是每当我尝试使用Massive.cs时,后者都是用于访问数据库的开源api Test fails from that file only. 测试仅从该文件失败。 Now, if I run the application, api is working fine. 现在,如果我运行该应用程序,则api工作正常。 I have created a different library file to access data base. 我创建了一个不同的库文件来访问数据库。

I seriously don't understand the error. 我严重不明白该错误。 It is just giving error that object reference is not set to an object. 对象引用未设置为对象只是错误。 But if I run the code, it works fine. 但是,如果我运行代码,它就可以正常工作。 I am using dynamic keyword as shown in link of api above. 我正在使用动态关键字,如上面的api链接所示。 Does that making problem with NUnit ? NUnit会造成问题吗?

Is there any other way to test in this type of Scenarios? 在这种情况下还有其他测试方法吗?

Here are the further details of the code, 这是代码的更多详细信息,

Test class is like this 测试课是这样的

dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });

var items = item.All();

Assert.AreEqual("Maggi", items.FirstOrDefault().Name);

Now, I have put test here. 现在,我在这里进行了测试。 Which gives error like shown in image, 出现如图所示的错误, 使用NUnit测试时出现错误

Now if I run code in console application, then code is working fine, code snippet is given below 现在,如果我在控制台应用程序中运行代码,则代码工作正常,下面给出了代码段

dynamic item = new Item();
        item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });


        var result = item.All();

        foreach (var i in result)
        {
            Console.WriteLine(i.Name + i.Description);
        }

        Console.Read();

Here, code is working and same thing is not working with NUnit Test. 在这里,代码可以正常工作,而NUnit Test不能正常工作。 Please have a look and help me out. 请看看并帮帮我。 Please let me know if any further information is needed from my side. 如果我需要进一步的信息,请告诉我。

Most probable explanation is that you haven't set up your connection string in the test project. 最可能的解释是您尚未在测试项目中设置连接字符串。
If you are using NUnit, just put it in app.config of your test project. 如果您使用的是NUnit,则将其放在测试项目的app.config中。

Solved... There is a issue with NUnit Testing. 已解决... NUnit测试存在问题。 It was not taking config file pefectly. 它没有完美地获取配置文件。 So, I made two changes. 因此,我做了两个更改。 Changes I have done in Project setting. 我在项目设置中所做的更改。

First change is to change Application Base to bin\\debug just give application base as this and then config file to .config to .exe.config and things are up and running. 第一个更改是将Application Base更改为bin \\ debug,仅以此为基础提供应用程序库,然后将配置文件从.config更改为.exe.config,这样就可以正常运行了。 :) :)

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

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