-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various improvements for TestCases decorator #644
Comments
Great points thanks for raising this one. I was looking additionally at improvements here to make it better for property testing. If you're able to send a pr around this it would be greatly appreciated. Otherwise happy to look at this :) |
The improvements mentioned here will be covered in #678 which will introduce a new decorator to avoid confusion with |
I chose Alsatian as the test framework for my recent projects specifically for two reasons:
I wrote a lot of tests to using the |
See here for some references: https://github.com/cashmoneyjs/cashmoney/tree/master/tests |
Thanks so much for this great feedback :) The goal of this replacement is to encourage better test writing without losing functionality. The problems I see with
We will be considering alternatives in the design, for example @TestProperties(fromArrays(
[1, 2, 3],
[4, 5, 6]
)) The goal being to have an explicit way of writing these tests so it's clear they are different, are more readable and we can start applying specific logic in these scenarios e.g. all arrays must be the same length. I'd love to get your input into this design or perhaps some alternatives if you have any ideas since you are using the existing solution quite heavily :) |
I agree that the name You could even consider |
For me I prefer the use of In terms of composition this means you can still create something more specific to your needs if necessary but I wanted to avoid doing this in the framework as In this specific case I`d expect something like const TestCaseGenerator = (...cases: Array<any>) => TestProperties(fromArray(...cases)); Alternatively we could curry these functions to make this process even easier? |
What would that look like from an end-user perspective? |
So using the snippet I noted above you should write the following @TestCaseGenerator([
[ "arg one", 1 ],
[ "arg two", 2 ]
])
public testWithArrayArgs(stringArg: string, numberArg: number) {
// test code
}
const AdminRolesCases = TestProperties(fromArray([ Role.Admin, Role.UserAdmin, Role.SuperAdmin ])); and used... @AdminRolesCases
public adminRolesDoSomethingSpecific(adminRole: Role) {
// check admins do something
} |
But what about handling for the current situation, where if |
You should be able to call that function e.g. |
The original point of me opening this issue was to not have to do that at all. Right now, even if my function is a generator the The only reason I can see for doing things this way is because the test framework wants to know how many tests there are before it starts running tests. Is there a reason for this? Otherwise, what's wrong with just modifying how |
I think there is a bit of confusion here. We're trying to do the same thing but in the design for the replacement of As a summary of the design so far In order to converge all use cases to a single implementation (generator) we need some helper functions to do that e.g. @TestProperties(numbers.from(0.05).to(1000.05).step(0.5), randomStrings.ofLength(8)) The above would build the required generators in order to run a lot of tests without the pain of writing them out or consuming a lot of memory. The additional benefit of this design we see is composability as we want people to create their own decorators that are useful in their domain. as mentioned above we can write const MyUsefulDecorator = TestProperties(numbers.from(0.05).to(1000.05).step(0.5), randomStrings.ofLength(8)); The above can then be reused again and again and even updated without having to change all the tests it affects. We also get a third potential benefit of a small performance increase / code simplification as we don't need to do any runtime type checking in order to implement different sorts of iterator. All I was trying to highlight in previous posts is the existing functionality will still exist in another form but in order to bring more benefits the syntax will be slightly different. How does that sound? |
Thank you for taking the time to lay everything out again in full, I appreciate it. It makes a lot more sense now and definitely looks like the right way forward 👍 |
No worries thanks for your patience. When we've got to a design we're happy with I'll update you with what things are looking like as it would be good to get your input and feedback on the design :) |
But this should be pretty close to what's already been discussed we're just ironing out details. |
It appears that there isn't any documentation for the
TestCases
decorator added by #414.Additionally, after inspecting the code it appears that it doesn't handle iterators (especially generators) very well. Instead of manually unrolling the iterator and then running all of the test cases, it would be ideal if it ran the tests one at a time. This seems more in line with the expectation of using an iterator, especially if memory usage is a concern.
The text was updated successfully, but these errors were encountered: