Question

The title is probably not very clear. I have the following example in mind:

an Authenticator object authenticates a user using credentials. It returns a AuthResult object. This AuthResult object says the authentication succeeded, or that it failed (and if so, why it failed, eg username not found).

How can I phrase this in a test? 'testShouldReturnAuthObjectWithStatusSuccessOnValidLogin'?

Was it helpful?

Solution

testValidLoginIsSuccessful or testIsSuccessfulOnValidLogin seems good enough for me.

For error tests, you could use something like testGetsCustomMessageOnUserNotFound

You should avoid putting implementation details in the method name.

OTHER TIPS

Without seeing how these tests are implemented, it seems from the naming that the observations are over-packed.

If this test fails, you'll have to do some digging to know if it is because (a) no AuthResult object was returned, or (b) status was not "success," and further, was there no AuthResult because the Authenticator never connected to the database or do some other required action?

I'd name the fixture When_told_to_authenticate_with_valid_credentials and then separate the assertions into two different observations:
1. should_return_an_AuthResult
2. should_be_successful

If you mock out those other classes as Samuel rightly suggested, you can further stipulate that the Authenticator is behaving as you expect:
3. should_connect_to_the_database
4. etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top