-2

I often read that each unit tests should test one logical 'thing'.

What do I do when the return value of a function is a dictionary?

Usually I equality check the entire dictionary against an expected result, but this leads to testing for results that perhaps aren't related to one specific test.

Should I be testing each individual key: value pair in different tests?

  • Unit tests are not always the most appropriate type of test. You can obtain a similar result, using less code, with a different type of test. – Frank Hileman Jul 27 '17 at 17:54
  • What type of test would that be? – Godron629 Jul 27 '17 at 18:43
  • The name depends on who you talk to, but technically it cannot be a unit test. You might call it an integration test or a composite test. – Frank Hileman Jul 28 '17 at 16:58
4

I often read that each unit tests should test one logical 'thing'. What do I do when the return value of a function is a dictionary?

By "one logical thing" it means one software component. If your test is testing more than one software component, it is by definition an integration test. In your situation the function is the one logical thing. Your function shouldn't be using any other component. If the function does have collaborators, they should be mocked. Each unit test for the function should pass an input to your function, and test the entire dictionary returned from the function as well as any assertions about the collaboration with other components.

  • 1
    That makes sense. I suppose testing individual results is pretty much just an extremely verbose way of testing the whole thing. I'll wait a day to see if there are any responses. – Godron629 Jul 26 '17 at 21:55
-2

I recently came by this article and it might help you

Testing your code is very important.

Getting used to writing testing code and running this code in parallel is now considered a good habit. Used wisely, this method helps you define more precisely your code’s intent and have a more decoupled architecture.

the site- http://python-guide-pt-br.readthedocs.io/en/latest/writing/tests/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.