unit testing在一起运行时失败,单独传递
所以我在unit testing中遇到了一些问题,我不能在这里复制和过去,但我会尽我所能。
问题似乎是,如果我逐个运行测试,一切都按预期工作,但如果我告诉它运行测试所有一起1/5将通过,
[TestMethod] public void ObjTest() { //Arrange - multiple ecus and items var t = new var(); t.itemNumbers = new List(); 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 tmp = new List(); //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."); }
所有的unit testing基本上都是副本和过去的chages到e.property并且可能更改为其中一个i数字,
测试旨在检查用户输入的边缘情况。
是否有一些我缺少的东西,以确保范围清除所有变量和测试之间的一切。 或强制串行执行。
我建议考虑Globals.masterList.Add(e);
假设您的unit testing在五个线程中执行。 这意味着Globals.masterList.Add(e);
将被执行五次或者masterList将被五个不同的线程修改。 然后你有下一行代码:
Assert.AreEqual("(12345 OR 55555) AND !65232", functionCalled(t.itemNumbers, Globals.masterList, ref tmp), "Wrong obj returned.");
functionCalled通过其他函数处理修改后的列表,作为结果,您可以从中获得不同的输出,结果是unit testing失败
上述就是C#学习教程:unit testing在一起运行时失败,单独传递分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/956681.html