3.5 KiB
3.5 KiB
| stage | group | info |
|---|---|---|
| none | unassigned | To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments |
Naming
Test names should form a readable sentence defining the purpose of the test. Our testing guide extends the Thoughtbot testing style guide. This page clarifies the guidelines, along with input from https://www.betterspecs.org/ and the RSpec naming guide
Recommended Approach
The following block generates a test named Plan wiki content creation when inside a project adds a home page
# `RSpec.describe` is the DevOps Stage being covered
RSpec.describe 'Plan', product_group: :knowledge do
# `describe` is the feature being tested
describe 'wiki content creation' do
# `context` provides the condition being covered
context 'when inside a project'
# `it` defines the expected result of the test
it 'adds a home page'
...
end
...
end
...
end
end
- Every
describe,context, anditblocks should have a short description attached - Keep descriptions as concise as possible.
- Long descriptions or multiple conditionals could be a sign it should be split up (additional
contextblocks)
- Long descriptions or multiple conditionals could be a sign it should be split up (additional
- The outermost
Rspec.describeblock should be the DevOps stage name - Inside that block is a
describeblock with the name of the feature being tested - Inside that block are optional
contextblocks with names that define what the conditions being tested arecontextblocks descriptions should begin withwhen,with,without,for,and,on,in,as, orifto match the rubocop rule
- The innermost
itblock describes the pass/fail criteria for the test - In
shared_exampleswith a single example aspecifyblock can be used instead of a nameditblock
Conventions flowchart
graph TB
rspec_describe{`RSpec.describe`\nis\nDevOps Stage Name?}
fix_rspec_describe[make `RSpec.describe DevOps Stage name]
describe_block{`describe`\nis\nFeature being tested?}
fix_describe_block[fix `describe` block name]
test_name{Test name longer\nthan 60 characters?}
shorten_sub[need to shorten sub names]
sub_names{`describe`, `context`, or `it` names\nlonger than 40 characters?}
shorten_name[shorten name]
context_correct{`context` block\ndescribes conditions\nof test?}
fix_context[rewrite `context` block starting with `when`, `with`, `without`, `for`, `and`, `on`, `in`, `as`, or `if` ]
if_test{`if` block\ndescribes test result?}
fix_if[rewrite `if` block]
test_name_complete[test name complete]
rspec_describe -- yes --> describe_block
rspec_describe -- no --> fix_rspec_describe
fix_rspec_describe --> rspec_describe
describe_block -- yes --> test_name
describe_block -- no --> fix_describe_block
fix_describe_block --> describe_block
test_name -- yes --> shorten_sub
shorten_sub --> shorten_name
test_name -- no --> sub_names
sub_names -- yes --> shorten_name
shorten_name --> test_name
sub_names -- no --> context_correct
context_correct -- no --> fix_context
fix_context --> test_name
context_correct -- yes --> if_test
if_test -- yes --> test_name_complete
if_test -- no --> fix_if
fix_if --> test_name