question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Increase Per-File Backend Test Coverage

See original GitHub issue

Background

Currently, we have 100% test coverage of our backend code. However, for many backend code files, this coverage is partly from the file’s associated test files and partly from test files for other backend code. For example, consider the following files:

  • util.py

    def parse_int(string_input):
        return int(string_input)
    
    def int_to_str(number):
        return str(number)
    
  • util_test.py: Tests for parse_int()

  • main.py

    def main():
      return int_to_str(5)
    
  • main_test.py: Tests for main()

Here we have 100% code coverage even though util_test.py only tests one of the functions in util.py because the other function is used by main.py, so it is tested indirectly.

Motivation

  1. Indirect test coverage tends to be lower-quality because it’s covered accidentally rather than by a deliberate test.
  2. Once we get full per-file backend test coverage, we can make the pre-push hook run backend tests for just the files that have been changed. This will let developers catch bugs earlier and speed up CI runs (since the load on CI will be lower).

Goal

The goal of this issue is to write tests so that every backend code file is fully covered by its associated test file. In other words, we want util_test.py to fully cover util.py. We call this “100% per-file coverage.” To meet this goal, we need to write tests for code that is currently tested indirectly (in the example above, we need to write tests for int_to_str() in util_test.py).

Coverage Tests

Our backend test runner (scripts/run_backend_tests.py) currently checks per-file coverage and will fail if that coverage is not 100% for any file associated with a test file not in scripts/backend_tests_incomplete_coverage.txt. There are a few important implications of this system:

  • The coverage checks can pass even if a backend code file has no associated test file at all. This is because adding entirely new test files is beyond the scope of the current work.
  • scripts/backend_tests_incomplete_coverage.txt functions as a list of test files that need more tests but are currently being ignored.

Procedure

To help us achieve 100% per-file backend test coverage, you can write tests in one of the files listed in scripts/backend_tests_incomplete_coverage.txt (copied as a task list below). Here’s how:

  1. Assign yourself to one of the tasks by putting your username at the end. For example:

    * [ ] core.controllers.base_test @your-username
    

    If you don’t have permission to assign yourself, leave a comment mentioning @U8NWXD and asking to be assigned.

  2. On your local computer, remove your assigned test module from scripts/backend_tests_incomplete_coverage.txt.

  3. Run the backend tests. To speed up the tests, you can run only your test module. For example, if you were assigned scripts.docstrings_checker_test, you could run:

    $ python -m scripts.run_backend_tests --test_target scripts.docstrings_checker_test --generate_coverage_report
    ...
    INCOMPLETE COVERAGE (69.0%): scripts.docstrings_checker_test
    Name                            Stmts   Miss  Cover   Missing
    -------------------------------------------------------------
    scripts/docstrings_checker.py     109     34    69%   61-67, 80-91, 104-109, 125-127, 133-142, 173-178
    -------------------------------------------------------------
    TOTAL                             109     34    69%
    ...
    

    Notice that the output identifies the lines of the code file being tested that need to be covered. In this example, we need to write tests for lines 61-67, lines 80-91, etc.

  4. Write tests! For help writing backend tests, see our backend tests wiki page. You may also find our debugging advice for backend tests helpful.

  5. Once the coverage checks pass when you run your assigned test, you can make a pull request.

How to Request a Task

To request a task to work on, leave a comment specifying which available task you want to claim. @U8NWXD will assign you by putting your username next to the task in the list below.

Note: If you are working on writing tests for multiple files at the same time, please combine them into a single PR to ease the burden on our testing infrastructure and reviewers.

Note that some files may appear twice because some files that had full line coverage were added again once we started tracking branch coverage.

Tasks

Available

  • core.controllers.acl_decorators_test
  • core.controllers.base_test
  • core.controllers.contributor_dashboard_test
  • core.controllers.creator_dashboard_test
  • core.controllers.domain_objects_validator_test
  • core.controllers.editor_test
  • core.controllers.feedback_test
  • core.controllers.learner_playlist_test
  • core.controllers.library_test
  • core.controllers.payload_validator_test
  • core.controllers.practice_sessions_test
  • core.controllers.profile_test
  • core.controllers.questions_list_test
  • core.controllers.reader_test
  • core.controllers.skill_editor_test
  • core.controllers.story_editor_test
  • core.controllers.subtopic_viewer_test
  • core.controllers.suggestion_test
  • core.controllers.topic_editor_test
  • core.controllers.topics_and_skills_dashboard_test
  • core.domain.app_feedback_report_domain_test
  • core.domain.app_feedback_report_services_test
  • core.domain.blog_services_test
  • core.domain.calculation_registry_test
  • core.domain.classifier_services_test
  • core.domain.collection_domain_test
  • core.domain.collection_services_test
  • core.domain.config_domain_test
  • core.domain.draft_upgrade_services_test
  • core.domain.email_manager_test
  • core.domain.exp_domain_test
  • core.domain.exp_services_test
  • core.domain.feedback_services_test
  • core.domain.fs_services_test
  • core.domain.html_cleaner_test
  • core.domain.html_validation_service_test
  • core.domain.image_validation_services_test
  • core.domain.interaction_registry_test
  • core.domain.learner_goals_services_test
  • core.domain.learner_group_services_test
  • core.domain.learner_playlist_services_test
  • core.domain.learner_progress_services_test
  • core.domain.opportunity_services_test
  • core.domain.platform_parameter_domain_test
  • core.domain.platform_parameter_registry_test
  • core.domain.question_domain_test
  • core.domain.question_services_test
  • core.domain.rules_registry_test
  • core.domain.search_services_test
  • core.domain.skill_domain_test
  • core.domain.skill_services_test
  • core.domain.stats_domain_test
  • core.domain.story_fetchers_test
  • core.domain.subtopic_page_domain_test
  • core.domain.suggestion_registry_test
  • core.domain.summary_services_test
  • core.domain.topic_services_test
  • core.domain.translation_domain_test
  • core.domain.user_domain_test
  • core.domain.user_query_services_test
  • core.domain.user_services_test
  • core.domain.visualization_registry_test
  • core.domain.wipeout_domain_test
  • core.domain.wipeout_service_test
  • core.jobs.transforms.validation.base_validation_test
  • core.jobs.types.base_validation_errors_test
  • core.platform.auth.firebase_auth_services_test
  • core.platform.bulk_email.mailchimp_bulk_email_services_test
  • core.platform.email.dev_mode_email_services_test
  • core.platform.taskqueue.cloud_taskqueue_services_test
  • core.platform.taskqueue.cloud_tasks_emulator_test
  • core.schema_utils_test
  • core.storage.base_model.gae_models_test
  • core.storage.collection.gae_models_test
  • core.storage.exploration.gae_models_test
  • core.storage.question.gae_models_test
  • core.storage.topic.gae_models_test
  • core.utils_test
  • main_test
  • scripts.build_test
  • scripts.common_test
  • scripts.concurrent_task_utils_test
  • scripts.install_python_prod_dependencies_test
  • scripts.install_third_party_test
  • scripts.linters.html_linter_test
  • scripts.linters.js_ts_linter_test
  • scripts.linters.other_files_linter_test
  • scripts.linters.pylint_extensions_test
  • scripts.linters.pre_commit_linter_test
  • scripts.pre_push_hook_test
  • scripts.run_e2e_tests_test
  • scripts.run_frontend_tests_test
  • core.domain.rights_manager_test

Assigned

Complete

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:228 (171 by maintainers)

github_iconTop GitHub Comments

2reactions
U8NWXDcommented, Apr 6, 2022
2reactions
U8NWXDcommented, Mar 23, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Building A Tool To Improve Go Codebase's Test Coverage
The reason being, one can always write assertion free/bad tests which will boost the overall code coverage metric, but still not be confident...
Read more >
4 Steps to Improve Your Test Coverage
Follow these 4 steps to improve your test coverage and provide your users with more robust and enjoyable mobile products.
Read more >
10 ways to ramp up automation test coverage
This backlog will need attention and time to improve on the code coverage. Create an automation backlog board. Automate the backlogs. Once the ......
Read more >
Increase basic test coverage
Some basic functionality is missing test coverage. Proposed resolution. Create tests for. unsubscribing aka disabling; tokens; user preferences ...
Read more >
Backend tests · oppia/oppia Wiki
yml ) that will fail if any test files are missing. Per-file coverage. Above, we discussed overall coverage, which measures how much of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found