Recall & Review
beginner
What is Factory Boy used for in Django testing?
Factory Boy helps create test data easily by defining blueprints (factories) for your models. It saves time and keeps tests clean.
Click to reveal answer
beginner
How do you define a simple Factory Boy factory for a Django model?
You create a class inheriting from <code>factory.django.DjangoModelFactory</code> and set the model inside a <code>class Meta</code>. Then define fields with default values.Click to reveal answer
beginner
What method do you call to create and save an instance using Factory Boy?
Use
FactoryClass.create() to make and save an instance to the database.Click to reveal answer
intermediate
How can Factory Boy help with related models in Django?
You can use SubFactory to create related model instances automatically when creating the main model instance.
Click to reveal answer
beginner
Why is Factory Boy better than manually creating test data in Django tests?
Factory Boy reduces repetitive code, makes test data consistent, and improves test readability and maintenance.
Click to reveal answer
Which class should a Factory Boy factory inherit from for Django models?
✗ Incorrect
For Django models, factories inherit from factory.django.DjangoModelFactory to integrate with Django ORM.
What does the
create() method do in Factory Boy?✗ Incorrect
create() makes a new instance and saves it to the database.How do you define a related model inside a Factory Boy factory?
✗ Incorrect
SubFactory is used to create related model instances automatically.
Which of these is NOT a benefit of using Factory Boy?
✗ Incorrect
Factory Boy helps with test data but does not run tests automatically.
Where do you specify the Django model inside a Factory Boy factory?
✗ Incorrect
The Django model is set inside a nested Meta class as the model attribute.
Explain how to create a Factory Boy factory for a Django model and use it to generate test data.
Think about the class structure and how to call the factory.
You got /4 concepts.
Describe how Factory Boy handles related models when creating test data in Django.
Focus on how factories connect to other factories.
You got /3 concepts.