1

I am starting an App Engine application. I started defining some simple models I will need. I want to write tests for my application (that would be the first time I've done that). I cannot see what I should be testing for. I already looked to how to do this (https://developers.google.com/appengine/docs/python/tools/localunittesting), but I just don't know what to test...

Here is my code so far:

class User(db.Model):
    email = db.EmailProperty()
    name = db.StringProperty()

class Service(db.Model):
    name = db.StringProperty(required=True)

class UserService(db.Model):
    user_id = db.ReferenceProperty(User,
                                   required=True,
                                   collection_name='user_services')
    service_id = db.ReferenceProperty(Service,
                                      required=True)
    access_token = db.StringProperty(required=True)
    refresh_token = db.StringProperty(required=True)

class LocalServer(db.Model):
    authentication_token = db.StringProperty(required=True)

class Task(db.Model):
    user_service_id = db.Reference(UserService,
                                   required=True,
                                   collection_name='tasks')
    local_server_id = db.ReferenceProperty(LocalServer,
                                           required=True,
                                           collection_name='tasks')
    creation_date = db.DateTimeProperty(auto_now_add=True,
                                        required=True)
    completion_date = db.DateTimeProperty(required=True)
    number_of_files = db.IntegerProperty(required=True)
    status = db.StringProperty(required=True,
                               choices=('created', 'validated', 'in_progress', 'done'))
Gwyn Howell
  • 5,125
  • 2
  • 28
  • 45
seven-down
  • 126
  • 10

1 Answers1

2

Quoting Wikipedia:

Intuitively, one can view a unit as the smallest testable part of an application.

Now, I don't know exactly what your application is supposed to do, but in general you don't have to test each specific class/model. What does this mean? Well, you don't need to test a feature like this: "what happens when I add two users, and then I want to filter them by a specific name?". You don't have to test it, because in that case you would test a GAE function, .filter(). Now, why should you test it? :) Google pays its developers for that!

But what if you write a "filter" method? What if you customize the filter() method? Then you must test them. I suggest you to read this answer. The question is about Django models, but actually it is valid for every framework or programming language.

Community
  • 1
  • 1
Markon
  • 3,892
  • 1
  • 24
  • 39