$30 off During Our Annual Pro Sale. View Details »

Full Clean Factories

Full Clean Factories

Researching the model instance factories available for Django and how well they create valid objects for our tests.

In this talk I present my research into various Django factories. Full write-up is available at http://jamescooke.info/django-factory-audit.html

James Cooke

October 11, 2016
Tweet

More Decks by James Cooke

Other Decks in Programming

Transcript

  1. Full
    Clean
    Factories
    James Cooke
    Licensed under the
    Creative Commons Attribution-ShareAlike 3.0 Unported License.

    View Slide

  2. Outline

    Problem

    Libraries

    Grading factories

    Factory features

    Results

    View Slide

  3. Problem

    View Slide

  4. Factories

    Django Fakery

    Factory Boy

    Factory Djoy

    Hypothesis[django]

    Mixer

    Model Mommy

    View Slide

  5. Grading factories: Test

    Two models: User and Item

    Two factories: UserFactory and
    ItemFactory

    Create 10 instances
    class Item(models.Model):
    name = models.CharField(
    max_length=1, unique=True)

    View Slide

  6. Grading factories: Grades

    RED: Creates invalid instances

    YELLOW: Raises exception

    GREEN: Creates valid instances

    View Slide

  7. Factories
    Factory ItemFactory UserFactory
    Django Fakery RED YELLOW
    Factory Boy RED RED
    Factory Djoy YELLOW GREEN
    Hypothesis[django] RED RED
    Mixer GREEN GREEN
    Model Mommy YELLOW GREEN

    View Slide

  8. Final points

    Factories are made of two parts

    Hypothesis could win

    Test code on GitHub:
    https://github.com/jamescooke/factory_audit/

    Full write-up tomorrow
    http://jamescooke.info/

    View Slide

  9. Thanks!

    @jamesfublo

    Ask questions

    Let’s talk more about testing

    Thanks for listening!
    Licensed under the
    Creative Commons Attribution-ShareAlike 3.0 Unported License.

    View Slide