简体   繁体   English

单元测试在一起运行时失败,单独传递

[英]Unit Tests fail when run together, pass individually

So I am having a few issues with my unit Tests, I cant just copy and past them here but I will give what I can. 所以我在单元测试中遇到了一些问题,我不能在这里复制和过去,但我会尽我所能。

The problem seems to be that if I run the tests one by one everything works as intended, but if I tell it to run the tests all together 1/5 will pass, 问题似乎是,如果我一个接一个地运行测试,一切都按预期工作,但如果我告诉它一起运行测试1/5将通过,

[TestMethod]

    public void ObjTest()
    {
        //Arrange - multiple ecus and items 
        var t = new var();
        t.itemNumbers = new List<ItemNumber>();

        obj e = new obj();
        e.property = "(12345 OR 55555) AND !65232";

        Globals.masterList.Add(e);

        ItemNumber i = new ItemNumber();
        i.num= "12345";

        ItemNumber i1 = new ItemNumber();
        i1.num= "55555";

        ItemNumber i2 = new ItemNumber();
        i2.num= "55556";
        t.itemNumbers.Add(i);
        t.itemNumbers.Add(i1); 
        t.itemNumbers.Add(i2);

        ICollection<Iinterface> tmp = new List<Iinterface>();

        //act, process the ecu and item lists
        ;
        functionCalled(t.itemNumbers, Globals.masterList, ref tmp);

        //assert, there should be only 2 added to the list
        Assert.AreEqual(1, tmp.Count, " ");
        Assert.AreEqual("(12345 OR 55555) AND !65232", functionCalled(t.itemNumbers, Globals.masterList, ref tmp), "Wrong obj returned.");

    }

All of the unit tests are basically a copy and past with the chages to e.property and possibly a change to one of the i numbers, 所有的单元测试基本上都是副本和过去的,其中包括对e.property的更改,并且可能更改为其中一个i数字,

the tests are designed to check edge cases cased by user input. 测试旨在检查用户输入的边缘情况。

is there something I am missing to ensure scope clears all of the variables and everything between tests. 是否有一些我缺少的东西,以确保范围清除所有变量和测试之间的一切。 or force serial execution. 或强制串行执行。

I propose to consider Globals.masterList.Add(e); 我建议考虑Globals.masterList.Add(e); Let's say your unit test executed in five threads. 假设您的单元测试在五个线程中执行。 It means that Globals.masterList.Add(e); 这意味着Globals.masterList.Add(e); will be executed five times or masterList will be modified by five different threads. 将被执行五次或者masterList将被五个不同的线程修改。 Then you have next line of code: 然后你有下一行代码:

Assert.AreEqual("(12345 OR 55555) AND !65232", functionCalled(t.itemNumbers, Globals.masterList, ref tmp), "Wrong obj returned.");

functionCalled deals with modified list by other functions, and as outcome you have different output from it and as result failed unit test functionCalled通过其他函数处理修改后的列表,结果是你有不同的输出,结果是单元测试失败

暂无
暂无

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

相关问题 为什么我的测试一起运行时失败,但单独通过? - Why do my tests fail when run together, but pass individually? Flurl&HttpTest:单元测试在全部运行时失败,但在单独运行时通过 - Flurl & HttpTest: Unit tests fail when Run All, but pass when run individually 为什么使用HostType(“ Moles”)进行的单元测试中的断言在单独运行时可以通过,而在一组测试中运行时却失败? - Why would an assert on a unit test with HostType(“Moles”) pass when run individually, but fail when run with a group of tests? 一起运行时单元测试超时,单独运行时成功吗? - Unit Tests timeout when run together, succeed when run individually? 单元测试在Visual Studio中“全部运行”但单独传递时失败 - Unit Tests Fail when “Run All” in Visual Studio but passes individually 单元测试在“全部运行”时失败,但在单次运行时通过 - Unit tests fail on Run All but pass when are run single 一些 Nunit 测试在组中失败,但在其他环境中单独运行时通过 - Some Nunit tests are failing in groups but pass when run individually in other env 运行所有测试时单元测试失败,但在调试时通过 - Unit Tests failing when I Run All Tests but pass when I Debug 我正在尝试在Visual Studio中运行所有测试,但是当我运行测试时,第一个测试将通过,但所有其他测试将失败 - I am trying to run all tests in visual studio, but when I run the the tests the first one will pass, but all the others will fail 解决方案在网络共享(LAN)上时,单元测试无法加载 - Unit Tests fail to load when solution is on a network share (LAN)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM