Skip to content

Instantly share code, notes, and snippets.

@halllo
Created November 19, 2012 21:25
Show Gist options
  • Save halllo/4114065 to your computer and use it in GitHub Desktop.
Save halllo/4114065 to your computer and use it in GitHub Desktop.
Testing Continuations?
public class ClassUnderTest
{
public static void ReturnAfter500ms(int value, Action<int> result)
{
Task.Factory.StartNew(() =>
{
Thread.Sleep(500);
result(value);
});
}
}
[TestClass]
public class TestingTheTesting
{
[TestMethod]
public void ReturnAfter500ms_ContinuationOnDifferentThread_TestShouldFail()
{
var expected = 4;
var actually = 3;
Action<int> continuation = i => Assert.AreEqual(expected, i);
ClassUnderTest.ReturnAfter500ms(actually, continuation);
}
}
@royosherove
Copy link

why are expected and actually variables with different values? I do not see anything that increments a value here.

@halllo
Copy link
Author

halllo commented Nov 23, 2012

Ok, I admit, the code was a bit confusing. Take a look at the updated code. The logic in the CUT is clearly wrong (it decrements instead of increments) but the test will always be green, because the assert in the continuation is reached in a different thread, when the actual test method has been long left. The test should fail in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment