Testing puzzles
Moderator: Forum Moderators
-
- Posts: 27
- Joined: November 20th, 2020, 5:07 am
Testing puzzles
Create a new file for unit tests
Parametrized test
Parametrized test has two advantages:
Installation guide says Building Wesnoth only requires Boost >= 1.56.
While macro
Per discussion at the pull request, using the new macro is fine.
Naming Unit Test
- Create a new file within
wesnoth/src/test
- Add the path of the new file to the list at
wesnoth/source_lists/boost_unit_tests
wesnoth/source_lists/boost_unit_tests
, but CMake didn't warn.Parametrized test
Parametrized test has two advantages:
- It allows running the same test for a set of parameters.
- It reports the values of the parameters upon failure of the test.
Example for Boost 1.59+
While macro
BOOST_PARAM_TEST_CASE
of Boost <= 1.58 enables parametrized, the macro has two problems:
- It doesn't automatically register the test.
- It can't work with more than one parameter.
BOOST_DATA_TEST_CASE
of Boost >= 1.59 is much better.Per discussion at the pull request, using the new macro is fine.
src/tests/utils
has a auto_parameterized.hpp
Naming Unit Test
- Format:
method_name_StateOfThis_allArguments_AllExpectedBehaviors
- Character limit: 100 characters
Example 1
Last edited by CrawlCycle on November 25th, 2020, 7:51 pm, edited 8 times in total.
-
- Posts: 27
- Joined: November 20th, 2020, 5:07 am
Re: Testing puzzles
How to name a unit test
Cast study 1
- https://stackoverflow.com/questions/155 ... -practices
- https://dzone.com/articles/7-popular-unit-test-naming
- https://docs.microsoft.com/en-us/dotnet ... -practices
- No double underscore.
method_name_StateOfThis_allArguments_AllExpectedBehaviors
.Cast study 1
- Name of the method is:
add_child
- State of this object before calling the method: Empty
- Argument provided to the method: simple key
- Expected behaviour of the method:
- The method appends an empty child to this object.
- The method returns the new child
add_child_EmptyThis_simpleKey_AppendAndReturnNewEmptyChild
test of add_child method of config
Last edited by CrawlCycle on November 25th, 2020, 7:50 pm, edited 2 times in total.
-
- Posts: 27
- Joined: November 20th, 2020, 5:07 am
Re: Testing puzzles
I don't like long unreadable names. But why do people still use that?
Until I know all of the reason, I probably would still use long names.
Alternatively, maybe I can write a custom struct that replaces a long name:
Until I know all of the reason, I probably would still use long names.
Alternatively, maybe I can write a custom struct that replaces a long name:
- Fields for holding the properties of the test
- An implicit conversion to string.
- Celtic_Minstrel
- Developer
- Posts: 2274
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Testing puzzles
I don't think the string conversion idea will work - you can't make it convert to an identifier, after all.