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 ReturnIncrementedAfter500ms(int value, Action<int> result)
{
Task.Factory.StartNew(() =>
{
Thread.Sleep(500);
result(value - 1);//BUG
});
}
}
[TestClass]
public class Tests
{
[TestMethod]
public void ReturnIncrementedAfter500ms_Takes1_Returns2()
{
var expectedOutput = 2;
var input = 1;
Action<int> continuation = i => Assert.AreEqual(expectedOutput, i);
ClassUnderTest.ReturnIncrementedAfter500ms(input, 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