Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help3403


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
 
Options:
RSS cloud
Jump to:

Unittest permanently modifies database?

1 of 419 articles shown, currently no other people reading this forum.
photo
From: Timothy F.
Date: Sun 24th May 2020, 10:20am
Actions: 
        Login-to-reply

 

"Alan Cheng" <22*4*1*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Hi, I wanted to clarify database behaviour that I'm seeing when running tests.
> 
> I've built my files as demonstrated during last week's workshop. It seems that when I 
> register a user into the test database, then run a system test which involves dropping 
> all users in the setUp and tearDown methods, the original user is also removed. Is 
> there some way to avoid this behaviour (i.e have the database restored to original 
> state once the test finishes)? Or is this even supposed to happen in the first place?
> 
> It seems pretty dangerous that the database is permanently modified by the tests, 
> especially if the db.dropall() is called. If someone forgets to switch from Config to 
> TestConfig, then there's a risk of losing all your data and having to revert to an 
> earlier commit or re-migrate your database.

Not a bad idea to have a guard at the top of your unittests to ensure you are in Testing 
config before you blindly execute tests.

Related articles

Unittest permanently modifies database? (all 3) RSS
├─ original   Fri 22nd May 2020, 4:30pm, Alan C.
├─ reply 1   Sat 23rd May 2020, 6:09pm, Akhil N.
└─ THIS   Sun 24th May 2020, 10:20am, Timothy F.
This Page


Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020