Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1233
Use setUpTestData instead of setUp for creating test data for a-plus unit tests.
What?
Unit tests in a-plus have used the setUp method for creating database entries for tests, which causes them to be created and destroyed separately for each test inside a test class. There is an alternative method called setUpTestData, which only creates the entries once and reuses the data for the whole test class, resulting in a considerable speedup when running tests.
Why?
Current a-plus unit tests require roughly 1/3 of the time required before this change. On my laptop:
Using setUp: Ran 245 tests in 232.683s
Using setUpTestData: Ran 245 tests in 70.508s
How?
Basically the only thing changed is replacing the setUp instance methods with setUpTestData class methods. In a few cases, the api tests used the same dataset as "normal" tests (course, exercise), so here a custom testcase class (with data definitions) was defined and inherited to both classes instead of TestCase. The edit_course > operations was not converted due to issues, but those tests take like a second anyway, so probably not worth a deeper investigation at this point.
Fixes #1233
Testing
The unit test suite was successfully ran using the updated code, but of course I cannot be sure these changes do not cause any tests to pass when they should not.
What type of test did you run?
Did you test the changes in
Translation
Programming style
Have you updated the README or other relevant documentation?
Is it Done?
Clean up your git commit history before submitting the pull request!