For example:[quote]Quote
[font='courier new']assert(my_variable == true);[/font][/quote]
Sure, it's nice and tearse for a programmer, but what if it were more fluent?[quote]Quote
[font='courier new']Assert::That(my_variable).Should().BeTrue();[/font][/quote]
Or a scenario where we want to check a range:[quote]Quote
[font='courier new']assert(!(my_variable >= min_value && my_variable <= max_value);[/font][/quote]
Oh crap, now we're getting more complex! But with a fluent syntax, it makes it more readable.[quote]Quote
[font='courier new']Assert::That(my_variable).Should().BeInRange(min_value, max_value);[/font][/quote]
Inspired by the brilliant .NET Fluent Assertions, I created Chamois, a header-only Fluent Assertion library for C++ Unit Testing.
The primary ways of expressing a test is as follows:[quote]Quote
[font='courier new']Chamois::Assert::That().Should().Be();
Chamois::Assert::That().Should().NotBe();[/font][/quote]
I currently support the following types:
- Integral numerics (short, int, long, float, double)
- String (via std::string/std::wstring, including const char* / const wchar_t*)
- Arrays (simple arrays)
- Pointers (naked pointers only)
- Any object by reference that supports the equality operator
Support for more standard library containers, smart pointers, etc is planned.
Currently, I only support the Microsoft's test framework assertions but I'll be adding more soon - including c-style assert for simple tests.
This is great