1

We're having a bit of a discussion in the office about how to implement good integration tests.

Example:
Account Creation
1. Create User
2. Add Role

One case we test is, if there is already a user with the same email address. For this, I first created a user (programmatically ) and then tried to create an account with the same email.

Now the argument was, that I should be just seed our DB with this existing user and ONLY try to create an account (not have the first CreateUser in the test). Since like this I also implicitly test the "CreateUser" part and it adds functionality to the test that is not necessary, which could lead the test to fail for the wrong reasons.

My point was that it's easier to create the user programmatically and that the CreateUser function is already tested elsewhere. And this way you have all data contained in this one test case, so it's easier to understand.

What do you guys think about this?

6
  • 1
    Might be important to note that if your test accesses a database, it is not a unit test. Commented Jul 29, 2016 at 14:26
  • 1
    What Vincent said. That's an integration test, not a unit test. Commented Jul 29, 2016 at 14:31
  • Fair enough. But at some point I have to check if the data goes into the database correctly and that we can retrieve it correctly. But anyway, that is a bit outside of the scope of this question. Commented Jul 29, 2016 at 14:33
  • Ok, changed the question. Commented Jul 29, 2016 at 14:34
  • 3
    At some point, you guys that are testing your databases in unit/integration tests have to start trusting your database to do the right thing. Mocking a database is fine, but all it really tells you is that you're making the call correctly, and if you make an error coding the test, it will tell you the wrong thing. If I had a preference, I would include the database in the test; at least that would be a real test. Commented Jul 29, 2016 at 14:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.