Class: Danger::AndroidUnitTestChecker
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::AndroidUnitTestChecker
- Defined in:
- lib/dangermattic/plugins/android_unit_test_checker.rb
Overview
This plugin provides methods to check for the presence of unit tests for newly added classes in a pull request.
Constant Summary collapse
- ANY_CLASS_DETECTOR =
/class\s+([A-Z]\w+)\s*(.*?)\s*{/m- CLASS_MODIFIER_DETECTOR =
/((?:\s|public|internal|protected|private|final|abstract|static|data|enum|sealed|value|annotation)*)class\s+([A-Z]\w+)\s*(.*?)\s*({|\n\n)/m- CLASS_MODIFIER_EXCEPTIONS =
[ /\s*data\s*/, /\s*private\s*/, /\s*enum\s*/, /\s*sealed\s*/, /\s*value\s*/, /\s*annotation\s*/ ].freeze
- DEFAULT_CLASSES_EXCEPTIONS =
[ /ViewHolder$/, /Module$/, /Button$/ ].freeze
- DEFAULT_SUBCLASSES_EXCEPTIONS =
[ /(Fragment|Activity)\b/, /RecyclerView/, /^BroadcastReceiver$/, /^ContentProvider$/, /Service$/, /View$/, /ViewGroup$/, /Layout$/ ].freeze
- DEFAULT_UNIT_TESTS_BYPASS_PR_LABEL =
'unit-tests-exemption'
Instance Method Summary collapse
-
#check_missing_tests(classes_exceptions: DEFAULT_CLASSES_EXCEPTIONS, subclasses_exceptions: DEFAULT_SUBCLASSES_EXCEPTIONS, path_exceptions: [], bypass_label: DEFAULT_UNIT_TESTS_BYPASS_PR_LABEL) ⇒ void
Check and warns about missing unit tests for a Git diff, with optional classes/subclasses to ignore and an optional PR label to bypass the checks.
Instance Method Details
#check_missing_tests(classes_exceptions: DEFAULT_CLASSES_EXCEPTIONS, subclasses_exceptions: DEFAULT_SUBCLASSES_EXCEPTIONS, path_exceptions: [], bypass_label: DEFAULT_UNIT_TESTS_BYPASS_PR_LABEL) ⇒ void
This method returns an undefined value.
Check and warns about missing unit tests for a Git diff, with optional classes/subclasses to ignore and an optional PR label to bypass the checks.
check. Defaults to DEFAULT_CLASSES_EXCEPTIONS. the check. Defaults to DEFAULT_SUBCLASSES_EXCEPTIONS.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dangermattic/plugins/android_unit_test_checker.rb', line 72 def check_missing_tests(classes_exceptions: DEFAULT_CLASSES_EXCEPTIONS, subclasses_exceptions: DEFAULT_SUBCLASSES_EXCEPTIONS, path_exceptions: [], bypass_label: DEFAULT_UNIT_TESTS_BYPASS_PR_LABEL) list = find_classes_missing_tests( git_diff: git.diff, classes_exceptions: classes_exceptions, subclasses_exceptions: subclasses_exceptions, path_exceptions: path_exceptions ) return if list.empty? if danger.github.pr_labels.include?(bypass_label) list.each do |c| warn("Class `#{c.classname}` is missing tests, but `#{bypass_label}` label was set to ignore this.") end else list.each do |c| failure("Please add tests for class `#{c.classname}` (or add `#{bypass_label}` label to ignore this).") end end end |