View Source Given.Case (given_exunit v1.22.196)
Extend ExUnit.Case
test cases with feature tests.
At the top of your test module:
defmodule MyApp.FeatureTests do
use ExUnit.Case, async: true
use Given.Case
end
A feature is often defined as a set of scenarios. The feature can be achieved
by grouping scenarios inside a standard ExUnit describe
block:
describe "feature 1" do
scenario "one", ~s[Given x When y Then z]
end
describe "feature 2" do
scenario "two", ~s""
Given x
When y
Then z
""
end
^ note the doc does not use triple quotes - your test cases should!
A scenario is a list of clauses. Each clause must start with one of GIVEN, WHEN, or THEN in UPPER or Title case. Newlines are counted as whitespace when separating clauses and are recommended but not required.
Clauses must appear in the order GIVEN WHEN THEN. If multiple clauses of the same kind are required then AND (or And) can be interspersed:
GIVEN pre-condition AND another pre-condition
WHEN action
THEN post-condition AND another post-condition
NOTE The error messages on the parser are not yet very descriptive!
If a scenario is required but has not yet been written you can write a
failing test as you would in ExUnit.Case
by writing a placeholder with a
name but without the prose:
describe "Leap seconds" do
scenario "handle 61 seconds in a minute"
end
Summary
Functions
Defines a named yet not implemented test.
Defines an ExUnit test with given name and prose.
Functions
Defines a named yet not implemented test.
Provides a convenient macro that allows a test to be defined
with a string, but not yet implemented. The resulting test will
always fail and print a "Not implemented" error message. The
resulting test case is also tagged with :not_implemented
.
Examples
scenario "handle leap seconds"
Defines an ExUnit test with given name and prose.
The test context cannot be matched but is passed into the first clause. For
more information on contexts, see ExUnit.Callbacks
.
Clauses must appear in the order GIVEN WHEN THEN. If multiple clauses of the same kind are required then AND (or And) can be interspersed:
Example
GIVEN pre-condition AND another pre-condition
WHEN action
THEN post-condition AND another post-condition