You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So far, tests are written and updated manually. In this issue, I'll be posting all the possible ways we've seen tests being written so far. I'll briefly mention the cons of each method and propose a template that could be used instead. Why do we need a template?
To solve issues that arise from the inconsistency in writing tests.
To create a semi-automatic way of writing and updating tests.
The main drawback of this method is that it's unclear what the test does. The name of the function can give a clue; however, function names cannot always be reliably used to describe a test, as they can often become overly long, making them hard to read:
This is arguably the best method since it allows us to use the description that comes from the problem specs, but it's still unclear how to choose an appropriate function name.
Also, test descriptions from problem specs are often very similar. It's incredibly easy to end up with duplicate names when someone reuses a previous test to create a new one, often through copy-pasting.
Taking all the above into account here's a proposed template:
One deftest per test from the problem specifications.
The order of deftests follows the order of the corresponding tests in the problem specifications.
The name of the function is the UUID of the test, prepended with test- or uuid-. This allows to quickly match an implemented test with the problem specs.
The "test description" is the test description from the .toml file, with the first letter capitalized.
The expected_value goes first, and the actual_value goes second. This is a common convention.
If the expected_value is a collection, a vector is used.
The actual_value should be a call to the tested function. If the function argument is a collection, a vector is used.
This isn't a perfect method—it still has some issues:
Users can see the function name. This isn't a major issue, considering the existing function names are often not very useful.
The test description may mention words like "lists," which can be confusing since the implementation uses vectors. This will be discussed in #671.
Note that the namespace is required without referring to any functions. This approach helps avoid issues where a function name might clash with a function name from clojure.core.
If the test line ends up being very long, splitting into multiple lines or using let is preferable:
So far, tests are written and updated manually. In this issue, I'll be posting all the possible ways we've seen tests being written so far. I'll briefly mention the cons of each method and propose a template that could be used instead. Why do we need a template?
Method 1
The main drawback of this method is that it's unclear what the test does. The name of the function can give a clue; however, function names cannot always be reliably used to describe a test, as they can often become overly long, making them hard to read:
Method 2
The main problem here is that it shows as one test being run, when in fact it's two.
Method 3
This is arguably the best method since it allows us to use the description that comes from the problem specs, but it's still unclear how to choose an appropriate function name.
Also, test descriptions from problem specs are often very similar. It's incredibly easy to end up with duplicate names when someone reuses a previous test to create a new one, often through copy-pasting.
Taking all the above into account here's a proposed template:
with the following rules:
deftest
per test from the problem specifications.test-
oruuid-
. This allows to quickly match an implemented test with the problem specs.expected_value
goes first, and theactual_value
goes second. This is a common convention.expected_value
is a collection, a vector is used.actual_value
should be a call to the tested function. If the function argument is a collection, a vector is used.This isn't a perfect method—it still has some issues:
Now on to some examples:
Note that the namespace is required without referring to any functions. This approach helps avoid issues where a function name might clash with a function name from
clojure.core
.If the test line ends up being very long, splitting into multiple lines or using
let
is preferable:I might edit this post later if I’ve missed anything.
The text was updated successfully, but these errors were encountered: