Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're right, django creates a test database inside your tests. From the docs:</p> <blockquote> <p>Tests that require a database (namely, model tests) will not use your “real” (production) database. Separate, blank databases are created for the tests. <a href="https://docs.djangoproject.com/en/dev/topics/testing/overview/#the-test-database" rel="noreferrer">full documentation</a></p> </blockquote> <p>Which is the correct thing to do. Unit test should be isolated from one another in order to avoid a dirty environment (a previous test forgets to remove a record/file/object it created and it affects the result of the other tests).</p> <hr> <p>What you are doing is called <a href="http://en.wikipedia.org/wiki/Functional_testing" rel="noreferrer">Functional Testing</a>. You are testing that your web application form submits, validates, saves, etc all in one test. Since the act of doing this implicates that many pieces of code run, it's not considered <em>unit</em> testing. When you perform these types of tests, your assertions should also be similar:</p> <ul> <li>assert thank you/welcome message is shown</li> <li>go to the user management page and assert new person is there</li> <li>check that they can log it</li> <li>etc</li> </ul> <p>This tests that your application functions correctly.</p> <p>The difference between the two types of testing is that Functional Testing tests <em>what</em> your application is doing, whereas Unit Testing tests <em>how</em> it's doing it. </p> <p>This is crucial because you could be saving your data in a number of ways:</p> <ul> <li>As JSON into a file</li> <li>As XML</li> <li>In a database locally</li> <li>In the cloud somewhere</li> </ul> <p>Your functional test doesn't really care <em>how</em> this is done, it just cares that when you go to a specific page, it gets the data. But unit test will drastically change depending on which way you're using.</p> <hr> <p>In your case, you are using both ways of testing. Selenium (opening a page, filling it out, submitting it) is testing <em>what</em> the application does (functional), but your assertions (was the data was saved to the database) is testing <em>how</em> you store the data (unit). </p> <p>So I suggest that you change your assertions to fit the rest of your test. And move the current ones into your unit tests: </p> <pre><code>def test_user_is_save(self): addUser(...) users = User.objects.all() self.assertEqual(len(users), 1) </code></pre> <p>This will test that your <code>addUser</code> method is working correctly (saving to the db), which is what <em>unit</em> test is about. And your current test will test that when you submit the form, the user sees the right thing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload