端末で実行するpython manage.py test appname
と、次のようになります: Ran 0 tests in 0.000s OK
これは私のtests.pyです:
from django.test import TestCase
import appname.factories
class UserProfileTest(TestCase):
def sample_data(self):
for i in range(0, 10):
user = appname.factories.UserProfileFactory.create()
私のmodels.py:
from django.db import models
class UserProfile(models.Model):
street = models.CharField(max_length=250)
tel = models.CharField(max_length=64, default='', blank=True)
postcode = models.CharField(max_length=250)
def __unicode__(self):
return self.tel
私の factory.py (ファクトリー ボーイ):
from appname.models import *
import factory
class UserProfileFactory(factory.Factory):
FACTORY_FOR = UserProfile
street = factory.Sequence(lambda n: 'Street' + n)
tel = factory.Sequence(lambda n: 'Tel' + n)
password = 'abcdef'