Property-based Tests (Experimental)
Note: These tests are designed to occasionally fail.
Property-based testing is a very powerful technique.
It automatically generates a large number of inputs for your code-under-test.
And when an input fails, it tries to reduce it to a simpler failing input.
IcuBlazor provides an interactive UI over the fantastic FsCheck library.
The following code is all you need to create property tests in IcuBlazor.
@inherits IcuBlazor.IcuTestSuite
@code {
public void test_a_property()
{
var pc = new PropertyChecker();
pc.Config.MaxNbOfTest = 50; // Config FsCheck
// create 50 arbitrary (char c, string str) values and test them
Check().Property(pc, "a demo property", (char c) => {
var str = pc.PickAny<string>();
return String.IsNullOrEmpty(str) || (str[0] != c);
});
}
public void test_base64_conversions()
{
var pc = new PropertyChecker();
Check().Property(pc, "base64 conversions", (string s) => {
//if (s == null) return true; // removed for demo
var encString = Str.ToBase64(s);
var decString = Str.FromBase64(encString);
return s.Equals(decString);
});
}
}