Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Unit test usecases/stories #107

Open
littlepea opened this issue Jun 5, 2020 · 2 comments
Open

Unit test usecases/stories #107

littlepea opened this issue Jun 5, 2020 · 2 comments

Comments

@littlepea
Copy link

It looks like dependency injection lands itself perfectly for testing, so that the business logic (stories) could be tested with injecting dummy callables for data access which would return test entities.

But the project doesn't have any tests, so it doesn't demonstrate how this approach contributes to better testability...

Btw, is it necessary to use attrs for stories or it could be replaced with dataclasses?

@proofit404
Copy link
Contributor

Hi, you are free to use attrs, dataclasses, pydantic, or old good __init__ method together with dependencies.
Usually, I override things with Injector.let in tests.
I replace only things I can't control like SMS gateways, API calls, SIP, Email, Facebook GraphQL API, etc.
A test usually calls stories for preparation, to do actual testing, and to validate the response.
So, it would be something like that:

def test_registeration():
    code = implemented.RequestCodeStory.let(twillio=lambda: ...).request(AnonumousUser())
    user = implemented.SubmitConfirmationStory.let(twilio=lambda: ...).submit(code)
    assert user.is_authorized()
  • no factory boy (never)
  • checks only business logic behavior
  • most of the tests are integration tests
  • unit tests can test entities only
  • do not ever test story step separately (delegate to the mapper, function, or a low-level object)

I hope that makes sense.

Have a good day 🎉

Best regards,
Artem.

@littlepea
Copy link
Author

Makes perfect sense, thanks, @proofit404 ! :)

I still think it would be great to add a few tests like this to this demo repo so it would speak for itself ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants