Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setUpTestData in tests #1348

Merged
merged 1 commit into from
Apr 10, 2024
Merged

Use setUpTestData in tests #1348

merged 1 commit into from
Apr 10, 2024

Conversation

sayravai
Copy link
Contributor

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?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Selenium tests.
  • Other test. (Add a description below)
  • Manual testing.

Did you test the changes in

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

Clean up your git commit history before submitting the pull request!

Copy link
Contributor

@ihalaij1 ihalaij1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@ihalaij1 ihalaij1 merged commit 0836875 into apluslms:master Apr 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Use setUpTestData in tests
2 participants