Best Practice for Selenium and Unit Testing

So, I'm experimenting with introducing unit tests of selenium in django 1.4 in several projects I'm working on.

The standard way to run my unit tests is to simply do ./manage.py test , and I use django-ignoretests to exclude certain django applications that I don't want to test (as needed).

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

What are some guidelines for separating and organizing selenium tests and standard unit tests?

+6
source share
2 answers

You can always group all your selenium tests in one package myapp/selenium_tests/ (as described here fooobar.com/questions/58680 / ... ), and then run manage.py test myapp.selenium_tests and the rest of the group under the word myapp/other_tests .

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

+5
source

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 these tests, add to the settings file: SKIP_SELENIUM_TESTS = True

This can be easily ported to a subclass of LiveServerTestCase or a simple decorator. If I had it in more than one place, it would be already.

+5
source

Source: https://habr.com/ru/post/914395/


All Articles