Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for organizing selenium tests and unit tests

So I am experimenting with the introduction of selenium unit tests in django 1.4 in a couple of projects I am working on.

The standard way to run my unit tests are simply to do ./manage.py test and I use django-ignoretests to exclude specific django apps that I do not want tested (as needed).

However, is there a way to configure my project so that I can decide to run only selenium tests when I want to and have ./manage.py test run only standard unit tests.

What are some best practices for segregating and organizing selenium tests and standard unit tests?

like image 750
Calvin Cheng Avatar asked Apr 28 '12 04:04

Calvin Cheng


Video Answer


2 Answers

You could always group all your selenium tests under a single package myapp/selenium_tests/ (as described here https://stackoverflow.com/a/5160779/1138710 for instance) and then run manage.py test myapp.selenium_tests and group the rest of tests under say myapp/other_tests.

Otherwise, I suppose you could write a test runner that checks for each test class whether it derives from LiveServerTestCase (see the docs: https://docs.djangoproject.com/en/dev/topics/testing/#defining-a-test-runner)

like image 64
Laurent S Avatar answered Sep 18 '22 23:09

Laurent S


For the test classes in question, I added the following decorator:

from django.conf import settings
@unittest.skipIf(getattr(settings,'SKIP_SELENIUM_TESTS', False), "Skipping Selenium tests")  

Then to skip those tests add to the settings file: SKIP_SELENIUM_TESTS = True

This could easily be wrapped into a subclass of LiveServerTestCase or a simple decorator. If I had that in more than one place, it would be already.

like image 33
Kris Kumler Avatar answered Sep 18 '22 23:09

Kris Kumler