-
Notifications
You must be signed in to change notification settings - Fork 0
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
[MOHAMED] 100% coverage on both function's tests #4
Conversation
- Implemented django mock tests for assumed branch cases on tests.py in web subdirectory of mygpo. - Need to clarify, and add better manual branch instrumentation, for proper testing and coverage enhancment
- Completed manual instrumentation over branches, and enhanced testing in tests.py for coverage enhancement
Adjusted format for test implementation, instrumentation, and coverage to match team formatting, and specific output to a text file.
Final major adjustment to episode_status_icon testing. Changed coverage.txt file location to be a universal project root, rather than a local directory. Full branch coverage achieved
Adjusted testing and instrumentation with additional helper methods to report coverage information to root
…ctions episode_status_icon and mark_outdated in class EpisodeUpdater Completed instrumentation, testing and coverage, with coverage reporting functionality. I have added additional instrumentation for hidden branches, and implicit branches. Branch instrumentation for EpisodeUpdater was only applied to mark_outdated as they had the only functional instrumentable branches in the class, with tests checking functionality of Updater, and also mark_outdated for proper functionality in Django. Please note, coverage.txt will be generated in the same directory of the test directory, regardless of local system. Please adjust as necessary to conform to team standards.
Had to change exporting behaviour for coverage reporting in accordance to team standards
…odeUpdater) - Modified branch naming conventions - Re-analysed and found instrumentatino and testing errors with EpisodeUpdater testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did a very good job on testing your 2 functions and achieving 100% branch coverage. The functions were not easy and you managed testing them thoroughly and to get them running. Great work!
cls.mock_episode = Mock() | ||
cls.mock_podcast = Mock() | ||
cls.updater = EpisodeUpdater(cls.mock_episode, cls.mock_podcast) | ||
cls.cumulative_branch_coverage = {"Branch 0": False, "Branch 1": False} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to use a map!
self.assertEqual(self.mock_episode.title, 'new-title') | ||
self.assertTrue(self.mock_episode.save.called) | ||
|
||
self.assertFalse(self.updater.branch_coverage["Branch 0"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't need to assert the branch coverage values, as they would be printed anyway on the file, but it does not negatively impact the code.
staticfiles_storage.url("delete.png"), | ||
"%s%s%s" | ||
% (_("This episode has been deleted"), date_string, device_string), | ||
) | ||
else: | ||
coverage_data['Branch 11'] +=1 # Branch 12 taken, implicit branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job at covering all branches.
self.assertEqual(result, mark_safe(expected)) | ||
|
||
def test_unknown_action(self): | ||
action = Action(action='unknown') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very thought through test cases!
Overview
Assigned functions:
Testing for function assignments:
Results
There was no testing, covering or branch instrumentation for the functions I have been assigned. Given their relative cyclomatic complexity, and use within the repository this seemed like a higher priority set of functions to instrument, and complete coverage over.
Though by looking at the overall repository, we tend to see a pattern of mock django test classes being executed in */tests.py per directory.
I then used this pattern for testing to implement testing for episode_status_icon in mygpo/web/tests.py, and class_ EpisodeUpdater (more specifically it's function mark_outdated) in mygpo/data/tests.py.
Relative branch coverage reports, are automatically generated as episode_status_icon__coverage.txt and EPISODEUPDATER_mark_outdated_coverage.txt in the directory mygpo/coverage/mohamed.
Coverage improvements for the base files shown by coverage reports generated by coverage.py are shown below:
episodes.py:
Before instrumentation and testing episode_status_icon:
After instrumentation and testing episode_status_icon:
feeddownloader.py:
Before instrumentation and testing EpisodeUpdater:
After instrumentation and testing EpisodeUpdater: