Problem with Unit Tests with similar names
I have very reproducible issue with unit tests. I am using R# 5.1 with VS 2010.
Example:
TestMethod] public void Foo_Bar() { Assert.AreEqual(1, 1); } [TestMethod] public void Foo_Bar_Two() { Assert.AreEqual(2, 2); }
I put breakpoints on each Assert and then debug ONLY Foo_Bar().
I hit the breakpoint on the Assert in Foo_Bar(), now when I hit F5 or whatever and complete the test I expect the debugger to stop and the test to be done as Passed... but the next thing that happens is it begins to execute Foo_Bar_Two().
Now - If I rename Foo_Bar_Two() to FooBar_Two() this doesn't happen. If I change it back to Foo_Bar_Two() it happens again.
TestMethod] public void Foo_Bar() { Assert.AreEqual(1, 1); } [TestMethod] public void FooBar_Two() { Assert.AreEqual(2, 2); }
If I call it Foo_Bar_Bar() it has the same issue. My first guess was that it was the underscores, but taking them out (FooBar, FooBarTwo, FooBarThree) resulted in the same behavior.
Now.. one more: if I add a third test and call it Foo_Bar_Three(), guess what? it runs all three tests! in alphabetical order! Foo_Bar, Foo_Bar_Three, then Foo_Bar_Two. And yes adding Foo_Bar_Four means that one fires second.
TestMethod] public void Foo_Bar() { Assert.AreEqual(1, 1); } [TestMethod] public void Foo_Bar_Two() { Assert.AreEqual(2, 2); } [TestMethod] public void Foo_Bar_Three() { Assert.AreEqual(3, 3); }
Next - say I have these tests:
TestMethod] public void Foo() { Assert.AreEqual(3, 3); } [TestMethod] public void Fooyou() { Assert.AreEqual(4, 4); } [TestMethod] public void Fooyoutoo() { Assert.AreEqual(5, 5); }
Debugging Foo() runs Foo, Fooyou, and Fooyoutoo - in that order. Debugging Fooyou runs Fooyou then Fooyoutoo.
If I add some Console.WriteLine calls to my tests though - only the Console.WriteLine in the selected method actually writes to the test output in the unit test session. Example below - debugging Bar() executes all four but only writes out "Bar":
TestMethod] public void Bar() { Assert.AreEqual(6, 6); Console.WriteLine("Bar"); } [TestMethod] public void bar() { Assert.AreEqual(8, 8); Console.WriteLine("bar"); } [TestMethod] public void bartwo() { Assert.AreEqual(9, 9); Console.WriteLine("bartwo"); } [TestMethod] public void BarTwo() { Assert.AreEqual(10, 10); Console.WriteLine("BarTwo"); }
But failed Assert are throwing exceptions in the chained methods. Example below - debugging Bar() throws an exeption on the Assert.AreEqual(8, 9) of BarTwo().
TestMethod] public void Bar() { Assert.AreEqual(6, 6); Console.WriteLine("Bar"); } [TestMethod] public void bar() { Assert.AreEqual(8, 8); Console.WriteLine("bar"); } [TestMethod] public void bartwo() { Assert.AreEqual(9, 9); Console.WriteLine("bartwo"); } [TestMethod] public void BarTwo() { Assert.AreEqual(8, 9); Console.WriteLine("BarTwo"); }
In all the above cases - If i choose to Run and not debug OR if I debug all tests in the test class this doesn't occur.
I confirmed this on multiple machines. All are running Windows 7 64-bit.
Sample solution attached.
Thanks!!
Attachment(s):
FooBarTests.zip
Please sign in to leave a comment.
Hello Chris,
Could you please copy the information from ReSharper | Help | About and paste
it here? Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
JetBrains ReSharper 5.1 C# Edition
Build 5.1.3000.12 on 2011-01-28T05:05:56
Licensed to: Christian Hawkins
Plugins: 5
#1. “Keymaps for ReSharper” v1.0.0.0 by “Howard van Rooijen - http://howard.vanrooijen.co.uk/blog”
#2. “Agent Johnson Plugin” v1.8.1.13216 by “Jakob Christensen.”
#3. “Agent Smith Plugin” v1.4.3.32120 by “Sergey Zyuzin.”
#4. Exceptional v0.3.1.0 by “Cofinite Solutions”
#5. “Settings Manager” v5.0.0.0 by “Roman "4ux-nbIx" Novitsky”
Visual Studio 10.0.30319.1.
Copyright © 2003–2011 JetBrains s.r.o.. All rights reserved.