Skip to content
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

Allow randomizing 'Guid' test arguments with [Random] #3899

Closed
julealgon opened this issue Jul 27, 2021 · 2 comments
Closed

Allow randomizing 'Guid' test arguments with [Random] #3899

julealgon opened this issue Jul 27, 2021 · 2 comments

Comments

@julealgon
Copy link

[Random] currently supports several primitive types (mostly numeric ones), but it does not work with Guid. To provide different values to a Guid argument, one has to manually provide them either via [TestCaseSource] or via [ValueSource].

In my experience, being able to easily provide different Guid values to a test is fairly useful. Currently, I'm doing this by using a ValueSource, which caused a different problem, forcing me to resort to hardcoded Guids instead of using Guid.NewGuid.

I'm aware that Guid randomization is different than the standard one using the Random class, so I'm not sure if it would be possible to have the same "seed" in discovery and execution phases to build the unique test names with the built-in values (probably not).

@julealgon
Copy link
Author

The last part of my post is probably not true as per this comment from @jnm2 :

In the meantime, that suggests the workaround you could use. Instead of Guid.NewGuid(), use TestContext.CurrentContext.Random.NextGuid().

I guess you could then easily leverage this for generating the random Guid values in a consistent manner like any other random values are created today.

@mikkelbu
Copy link
Member

mikkelbu commented Apr 9, 2023

Closed by #3951

@mikkelbu mikkelbu closed this as completed Apr 9, 2023
@mikkelbu mikkelbu added this to the 4.0 milestone Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants