To quote the "Way of Testivus",
A bad test is better than no test
Making sure that your test tells you that the code works is the point of the test. When you are writing tests for code that has already been written, you are setting things up so that you can refactor it and be confident that you have not broken any current functionality. If the test fails for no apparent reason, then the test is bad and should be fixed. As long the test ensures the functionality of your application, the test has some value.
Writing these tests gives you confidence in your ability to refactor that code later on. Because if you have done it right, the test will still pass. You are giving yourself the confidence to change that code and not have to worry about breaking any old functionality.
Uncle Bob had a recent blog entry regarding this:Uncle Bob had a recent blog entry regarding this:
If you have a test suite that you trust so much that you are willing to deploy the system based solely on those tests passing; and if that test suite can be executed in seconds, or minutes, then you can quickly and easily clean the code without fear.
Your example test isn't all that good but it gives you more confidence that any changes you make will not affect the functionality. You want to check that for a given state the method will output a specific response. You trying to test what the code does rather than what the code is. For legacy code like this, you will end up with tests that are more "functional" rather than "unit".
Does having this test give you more confidence that any changes to the application did not result in the code being broken? If not, then your test is not useful and you should get rid of it or change it. Untested code will paralyze any useful changes that you can make later.
"We can't make that change because we don't know everywhere that it is being used!" Your tests make that argument moot. You know that the code all works because all the tests pass.
Tests also do not ensure bug-free code. Your code may still have bugs but when they are discovered and you add a new test duplicating it. You ensure that that bug NEVER happens again because then that test will fail. And as long as you are running your tests often, this bug will always be checked for.