MatrixAttributes, ArgumentsAttributes, and Arrays #4596
mitchcapper
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Interestingly Arguments seems to be usable in much the same way Matrix can be used as:
public async Task MyTest([Arguments(["HI","Hello"])] String b) {}generates matrix tests.
I do see several areas in the code though where matrixattribute is specifically checked and it doesn't look like Arguments gets converted somewhere so I am not sure what the full ramifications are. Clearly it doesn't support exclude.
Do to convenience features this:
public async Task MyTest( [Arguments(["HI","Hello"])] String[] b)doesn't exactly do what one might expect, as it just matrix's it with two 1 item arrays.
In terms of actually using an array with Matrix/Arguments the syntax is a bit cumbersome:
[Matrix([new string[]{"Test1", "Test4"}])]It was easy enough to write a MatrixArray attribute (and one could presumably do an ArgumentsArray attribute as well) like:
and then if you just need to pass one value for the array you can use the basic syntax of:
public async Task MyTest( [MatrixArray(["HI","Hello"])] String[] b)and its quite clean.
Using an overload one can even support N based test arrays, its a bit hacky but it works well. It even allows you to pass a null value to the parameter as long as it isn't the last value you pass.
and it lets you continue to use the nice collection syntax:
[MatrixArray(["Test1", "Test4"],["Test1", "Test5"],["test9"])] string[] testsNot sure its worth including in tunit but it can make some tests much easier to read. The same example currently requires:
[Matrix([new string[]{"Test1", "Test4"}],[new string[]{"Test1", "Test5"}],[new string[]{"test9"}])] string[] testsBeta Was this translation helpful? Give feedback.
All reactions