The rules are:
- It must be a unit test (so don't touch the file system).
- The public signature for
CodeUnderTest
must not be changed.can be extended not reduced - You're allowed to use DI/your favorite mocking framework.
- You can only add code where you see /**/.
[Test]
public void Test()
{
/**/
var text = CodeUnderTest.GetUpperText("foo.txt" /**/);
Assert.That(text, Is.EqualTo("BAR"));
/**/
}
public class CodeUnderTest
{
/**/
public static string GetUpperText(string path /**/)
{
var text = File.ReadAllText(path);
return text.ToUpperInvariant();
}
/**/
}
Please comment below or tweet me @jcansdale.
I like the way you haven't touched the
CodeUnderTest
interface at all. That's probably about as clean as you can make it. Easy to forget to resetImp
though.Here it is written using the library I've been working on:
You can find more information here:
https://github.com/jcansdale/StaticMocks
I'd be interested to hear what you think. ๐