I am writing unit tests for a simple user model in rails and just started thinking about how I write tests.
There seems to be positive testing:
test "password should match the password_confirmation " do
user = User.new(
:email => "email@mail.com",
:password => "password",
:password_confirmation => "password")
assert user.valid?, "did not save user even though password matches confimation"
end
and negative testing:
test "password should not be valid with mismatching password_confirmation " do
user = User.new(
:email => "email@mail.com",
:password => "password",
:password_confirmation => "doesnotmatch")
assert user.invalid?, "saved user with mismatching password_confirmation"
end
Is it superfluous to include both tests in your test suite or is it a good practice?
Have a look at TDD. When you can move on?, that explains when you are ready with your tests (and code) and can move on. In you example, that means:
After that, you need another test to prove that your implementation is not sufficient. When you have written e.g.
you need another test case to prove that wrong.
I see the following cases:
So you would need 4 test cases for that.