C++ Voyager Test Framework
Voyager is a simple and handy C++ Unit Test framework. It is designed to be beautiful and expressive both. Try it to feel it!
Installation
To add Voyger to your new or existing project, add it to a subfolder as a submodule using following git command:
git submodule add https://github.com/anafro/voyager Path/To/Voyager/Folder
Then just update your CMakeLists.txt with following code:
# --- Voyager Test ---
add_subdirectory(Path/To/Voyager/Folder)
target_link_libraries(YourProjectName VoyagerLibrary)
And that's it! Easy, isn't it? :)
Requirements
Voyager can be used only from C++11 and higher.
Adding tests
To add a new test, write:
Voyager::test("Test Name", [](auto& shouldBe) {
// Your test case will be here
});
Test name should be in this form: all of the words are separated with a space and capitalized. If you don't follow this form, it won't cause an error, but we are highly recommend to follow it.
Writing tests
Write your code as usual - there are no restrictions. There are some functions that will help you to test:
Important: if some of the test functions fails, test won't be stopped! To stop test execution, just
return
from it.
equalTrue
shouldBe.equalTrue(bool expression, std::string messageIfFailed);
If expression is not true, test will fail.
equalFalse
shouldBe.equalFalse(bool expression, std::string messageIfFailed);
If expression is not false, test will fail.
failed
shouldBe.failed(std::string message);
Fails the test unconditionally. It will be helpful, if, for example, your code should not throw any exception, but when it does, you'll write failed(...)
Running tests
To run all the tests, use Voyager::run();
Example test
Voyager::test("Water Boiling", [](auto& shouldBe) {
Water water;
water.boil();
shouldBe.equalTrue(water.getTemperature() == 100);
});
Voyager::test("Water Freezing", [](auto& shouldBe) {
Water water;
water.freeze();
shouldBe.equalTrue(water.getTemperature() == 0);
shouldBe.equalTrue(water.getState() == SOLID);
});
Voyager::run();
Issues
If you discover any issues or problems in Voyager, please, send an email to Anafro via [email protected]
License
The Voyager Test framework is open-sourced software licensed under the GNU General Public License v3.