-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
Goal
Make writing input testing easier, readable and more robust
How
Simplifying syntax for supplying many arguments to Test functions
Currently you'd have to pass in multiple TestCase decorators which is fine but takes time and lines often resulting in not enough tests being run.
Instead if we use generators this could ensure a load of tests get run against functions testing them with an assortment of inputs ensuring they are robust.
@TestProperties(TrueAndFalse)
@TestProperties(Numbers.random().generate(100))
@TestProperties(Strings.ofLength({ over: 42 }).generate(500))
@TestProperties(Integers.random({ between: { lowerLimit: 0, upperLimit: 42000000 } }).generate(1000))
@TestProperties(Arrays.ofLength(6).fill(() => "some string").generate(42))
@TestProperties(Objects.with(o => o.property = "something").generate(24))Further to this we could supply fuzz style generators to ensure edge cases are caught.
@TestProperties(Numbers.edgeCases)
@TestProperties(internationalNames)
@TestProperties(internationalPhoneNumbers)Why not TestCases?
The TestCases decorator was a great start on this idea but there are a few things we want to improve upon.
- it takes in more than generators - we want to stick to generators for a clearer way to achieve this sort of testing
- it can be confusing how to pass in multiple arguments, now we'd write
@TestProperties(Numbers.random().generate(4), Numbers.random().generate(4))(Might want to think about this how we can ensuregenerate(4)is called on both. Maybe a wrapper of some sort?) - it is too close to
TestCasewant it to be named sufficiently different to ensure no confusion - it draws all cases into memory immediately, we want to move to generating values when we need them at runtime
What will we provide?
-
TestPropertiesdecorator in core to enable usage of generators - a set of predefined generators to get people started in a separate package -
alsatian-property-testing - helper functions to create custom generators