AdamMc331
AdamMc331

Reputation: 16691

Best practice for organizing automated testing?

I am writing an automated testing for an application and currently have around 150 test cases. Everything runs fine, but as the tests keep growing, I continuously run into the problem of figuring out how to organize the test cases.

Some tests will rely on previous tests (e.g. I can't log in until I've opened the application, I can't preform an action until I've logged in). At run time, I currently have a UI that allows the user to select which test cases to run, and it gets tricky trying to sort them once I have this list.

I feel that it would not be worth my time to have a predefined order for the test cases because not all will be run each time, and I would have to update this list each time I add a new test.

Does anyone with experience in automated testing, or testing in general, have any recommendations?

Note: I tried to add an integer flag to each test, and then order them that way, but that caused a lot of problems and any time I added a new test that occurred in the middle some tests had to be shifted (and that is a pain for 150+ test cases).

EDIT

I would just like to clarify another example for tests that may rely on each other, not just logging in or opening the application. For this software, the user can upload data in the application. They can then go and download a report for this data. Obviously, if the user only selects the 'download' test, there's nothing I can do. However, if the user selects 'upload' and 'download', I need a way to ensure that upload is preformed first.

Upvotes: 2

Views: 2409

Answers (1)

artm
artm

Reputation: 8584

Tests shouldn't rely on previous tests to run. What if you want to run "log in" tests only without running "open app" tests. Each test should have its own setup which will setup everything for the test to run on its own. If you want to test upload, you test that your application uploads files to the server successfully. If you want to test download, first you upload files to your server in your test setup, then test that uploaded files in your server can be downloaded.

Tests shouldn't care/rely on what happens before them, otherwise your tests might fail not because your code doesn't work, but because your tests don't work. Then you'll be wasting time trying to figure out why your code fails, when it's in fact the test that fails. Look into testsetup and testclear, every test sets up whatever it needs to run and then once it's finished it clears up after itself, so every test is clear of other tests.

Upvotes: 4

Related Questions