Those silly tests
Just got a rather pointed reminder why you should try to get as many tests as possible. The code is:
public override void Execute() { Version version = typeof (VersionCommand).Assembly.GetName().Version; Writer.WriteLine("VERSION " + version); }
And the test is:
[Test] public void Will_return_assembly_version_as_memcached_version() { var stream = new MemoryStream(); var cmd = new VersionCommand(stream); cmd.Execute(); Assert.AreEqual("VERSION " + typeof(VersionCommand).Assembly.GetName().Version + "\r\n", ReadAll(stream)); }
Now, tell me why this is not a stupid test & useless test.
Comments
I can spot two potential points:
The Version property returns System.Version, which is not plussable with string (does that even compile?).
"\r\n" should be Environment.NewLine, or the test will fail on non-Windows environments.
But from the test name, I understand it has to do with caching, so IDK.
Yes, it compiles. + for string == + .ToString(),
\r\n are part of the protocol, so we will leave that aside
I am assuming that Writer.WriteLine writes to the memory stream.
Your test is valid because you want to make sure that what you write to the stream is done so correctly by Writer.WriteLine (and that the writer is actually writing to your stream), which can be tested by reading the stream and checking the content.
You might also be checkin that writing to the stream has left the position in the stream on the right place for reading it afterwards. (guessing a bit here because I don't know what the specifications are and how you want to work with the stream, do you keep it open or not , do you seek to the beginning etc)
Also, I am hoping that you don't have another VersionCommand class in another assembly, and that you are testing here if your using statement is correct in the unit test.
You get the version the same way with "Execute"?
I mean, if you want to verify the version number, you'd better not to use the same way of the implementation to get the version number of the assembly --
typeof(VersionCommand).Assembly.GetName().Version
testers should try them best to make the test fail.
Or I misunderstood something?
I'm guessing the ReadAll method is returning an empty string in your test method as you didn't flush the stream in the Execute method?
Deparcq,
DING DING DING DING!
That is the error that the test exposes
Oh so subtle. It cracks me up to see such a simple and seemingly pointless test catch such a serious flaw.
Comment preview