简体   繁体   English

为什么我的NUnit测试不会失败?

[英]Why are my NUnit Tests NOT failing?

I have NUnit test code like this: 我有这样的NUnit测试代码:

[Test]
public void TestHHSInterface()
{
    var HHSClient = IOC.container.Resolve<IHHSClient>();

    var s = HHSClient.GetTestMessage("Rupert", "Pupkin");

    Assert.Greater(s.Value.Length, 0);
}

[Test]
public void TestHHSDeliveryInterface()
{
    var Delivery = IOC.container.Resolve<IHHSDelivery>();

    var i = Delivery.GetCount();

    Assert.Greater(i, 42); // was 17; returns 18
}

[Test]
public void TestHHSDeliveryItemInterface()
{
    var Delivery = IOC.container.Resolve<IHHSDeliveryItem>();

    var i = Delivery.GetCount();

    Assert.Greater(i, 42); // was 19; returns 36
}

The TestHHSDeliveryInterface() test (IHHSDelivery) returns 18, so asserting that it is greater than 42 should make it fail. TestHHSDeliveryInterface()测试(IHHSDelivery)返回18,因此断言它大于42应该使它失败。 Similary, TestHHSDeliveryItemInterface() returns 36, so its assertion should also fail. 类似地,TestHHSDeliveryItemInterface()返回36,因此其断言也应该失败。 But they all "pass": 但是他们都“通过”:

在此处输入图片说明

Also, I don't understand why only two tests are shown beneath \\Integration Test\\HHSClientIntegration Tests, when there are three, as shown in the code above. 另外,我不明白为什么\\ Integration Test \\ HHSClientIntegration Tests下只显示两个测试,而如上面的代码所示,却有三个。

UPDATE UPDATE

Pierre-Luc Pineault: You might be right, but even when I reverse it: Pierre-Luc Pineault:您可能是正确的,但是即使我撤消了它:

Assert.Greater(42, i);

...it still passes. ...它仍然通过。

UPDATE 2 更新2

I'm not sure what exactly I need to check to follow up on CodeCaster's suggestion to " Check that you're testing the assemblies containing the code you wrote (Debug/Release, different directory), especially given your remark that you see lest tests in the runner than there are in code. " 我不确定要遵循CodeCaster的建议“ 检查您是否正在测试包含所编写的代码的程序集(调试/发布,其他目录),特别是考虑到您会进行最少测试的说明,我到底需要检查什么” 在运行程序中比在代码中要多。

Following are some things that may be noteworthy; 以下是一些可能值得注意的事情; let me know what I'm missing/should look for yet. 让我知道我想念/想要的东西。

The Build property page for the Test project says: Test项目的Build属性页显示:

Configuration: Active (Debug)
Output path: bin\Debug

App.config contains this line: App.config包含以下行:

<compilation debug="true" targetFramework="4.5" />

HHS.Web.Tests.nunit contains: HHS.Web.Tests.nunit包含:

<NUnitProject>
  <Settings activeconfig="Default" />
  <Config name="Default" binpathtype="Auto">
    <assembly path="bin\Debug\HHS.Web.Tests.dll" />
  </Config>
</NUnitProject>

(that's the entire contents of HHS.Web.Tests.nunit) (这是HHS.Web.Tests.nunit的全部内容)

UPDATE 3 更新3

In response to some of the comments below (CodeCaster, OnABauer), I don't know if this helps, but the solution has 50 projects (of which I am working on just a few); 对于下面的一些评论(CodeCaster,OnABauer),我不知道这是否有帮助,但是该解决方案有50个项目(我只在其中几个项目); in "my world," the Startup Projects are three libraries/DLLs, specifically HHS.API, HHS.Web, and HHS.Web.Tests are set to "Start"; 在“我的世界”中,启动项目是三个库/ DLL,特别是HHS.API,HHS.Web和HHS.Web.Tests设置为“开始”; all the others are set to "None" 所有其他都设置为“无”

The Debug page of HHS.Web.Tests has "Start external program:" set to "C:\\Program Files (x86)\\NUnit 2.6.3\\bin\\nunit.exe" and "Command line arguments:" set to "C:\\project\\sscs\\CStore\\Development\\Development\\HHS.Web.Tests\\HHS.Web.Tests.nunit" HHS.Web.Tests的“调试”页面的“启动外部程序:”设置为“ C:\\ Program Files(x86)\\ NUnit 2.6.3 \\ bin \\ nunit.exe”,“命令行参数:”设置为“ C :\\项目\\ SSCS \\ CStore \\开发\\开发\\ HHS.Web.Tests \\ HHS.Web.Tests.nunit”

UPDATE 4 更新4

CodeCaster recommended, "Compare the full path from the test runner with your output path" CodeCaster建议:“将测试运行器的完整路径与输出路径进行比较”

How can I determine both things ("the full path from the test runner" and "[my] output path")? 如何确定两者(“来自测试运行器的完整路径”和“ [我的]输出路径”)? Is the path above (C:\\project\\sscs\\CStore\\Development\\Development\\HHS.Web.Tests\\HHS.Web.Tests.nunit) the test runner path? 上面的路径(C:\\ project \\ sscs \\ CStore \\ Development \\ Development \\ HHS.Web.Tests \\ HHS.Web.Tests.nunit)是测试运行程序路径吗? Or...??? 要么...???

UPDATE 5 更新5

As can be seen in the scream shot above, TestHHSDeliveryInterface shows up in the list of tests (supposedly) being run. 从上面的尖叫声中可以看出,TestHHSDeliveryInterface显示在正在运行的测试列表中(据说)。 So one would think that TestHHSDeliveryItemInterface would show up there, too. 因此,人们会认为TestHHSDeliveryItemInterface也将出现在此处。 After all, all of the places where TestHHSDeliveryInterface appears in the code, TestHHSDeliveryItemInterface does, too: 毕竟,在代码中出现TestHHSDeliveryInterface的所有地方,TestHHSDeliveryItemInterface也会出现:

HHSClientIntegrationtests: HHSClientIntegrationtests:

[Test]
public void TestHHSDeliveryInterface()
{
    var Delivery = IOC.container.Resolve<IHHSDelivery>();

    var i = Delivery.GetCount();

    //Assert.Greater(i, 42); // was 17; should return 18
    //Assert.Greater(42, i); <= same result (passes)
    // Seeing if it's running at all
    Assert.Fail(); // <= Test still passes, so something is very fishy here...
}

[Test]
public void TestHHSDeliveryItemInterface()
{
    var Delivery = IOC.container.Resolve<IHHSDeliveryItem>();

    var i = Delivery.GetCount();

    Assert.Greater(i, 42); // was 19; should return 36
}

HHSClientPlayTest: HHSClientPlayTest:

[Test]
public void TestHHSDeliveryInterface()
{
    var HHSDelivInterf = IOC.container.Resolve<IHHSDelivery>();
}

[Test]
public void TestHHSDeliveryItemInterface()
{
    var HHSDelivItemInterf = IOC.container.Resolve<IHHSDeliveryItem>();
}

HHSClientUnitTest: HHSClientUnitTest:

[Test]
public void TestHHSDeliveryInterface()
{
    var HHSDelivInterf = IOC.container.Resolve<IHHSDelivery>();
}

[Test]
public void TestHHSDeliveryItemInterface()
{
    var HHSDelivItemInterf = IOC.container.Resolve<IHHSDeliveryItem>();
}

And every place in the code where IHHSDelivery exists, there is a corresponding block of code for IHHSDeliveryItem... 在代码中存在IHHSDelivery的每个位置,都有一个对应的IHHSDeliveryItem代码块...

Instead of specifying a .nunit file in the project's Start Options, specify the test dll name without any path info. 而不是在项目的“开始”选项中指定.nunit文件,而是指定测试dll名称而不包含任何路径信息。 If this file is being rebuilt each time, it should guarantee you are loading the correct file. 如果每次都在重建此文件,则应保证您正在加载正确的文件。

If you set a breakpoint on the Assert, does the return value match what you expect? 如果您在断言上设置了断点,返回值是否符合您的期望? If not, you are either dealing with nunit-agent.exe or you are not recompiling your test assembly each time. 如果不是,则说明您正在处理nunit-agent.exe,或者不是每次都在重新编译测试程序集。

To verify you are using the correct assembly, use Process Explorer from the Sysinternals Suite to locate dll actually loaded by NUnit. 若要验证您使用的是正确的程序集,请使用Sysinternals Suite中的Process Explorer查找NUnit实际加载的dll。 Delete that assembly and recompile. 删除该程序集并重新编译。

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

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