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

Nested TestFixtureSource type #2585

Closed
mitchellmaler opened this issue Nov 29, 2017 · 6 comments
Closed

Nested TestFixtureSource type #2585

mitchellmaler opened this issue Nov 29, 2017 · 6 comments

Comments

@mitchellmaler
Copy link

Hello,

I have a use case to run selenium CMS tests based off of configuration files. The idea is they enable which browser to run as and then provide an array of URLs that the CMS provides for. I then would have a IEnumerable for the browses and one for the URLs. I would like the TestFixture to generate a Driver for each enabled browser and then for each url run each of the test methods in the class.

The setup would generate the webdriver/browser session and then navigate to the current url.

I have been successful on adding a single IEnumerable in a base class that does all the setup. I then tried to add a second TestFixtureSource to the actual fixture but that doesn't seem to work.

If was hoping to see if this is even possible and if not are then any other ideas. I would rather not add a TestCaseSource on each method since it would be a lot of duplicate code.

@CharliePoole
Copy link
Contributor

As you discovered, Fixtures don't work with multiple sources. NUnit only gets to construct the fixture once, with one set of parameters, so only one source can be allowed. Currently, the only NUnit-powered option is to use TestCaseSource on the methods.

To implement this with one fixture source, you would have to include the Driver along with the other arguments. Your internal logic in the source could be implemented with nested loops and yield the appropriate values in the inner one.

For longer term, this sort of use case might be a motivator for allowing parameterized OneTimeSetUp on a fixture.

@mitchellmaler
Copy link
Author

mitchellmaler commented Nov 30, 2017

Okay that makes sense. I think creating a type that holds the driver and url and throwing that into IEnumerable would work.

Having a parametrized OneTimeSetUp was actually something I went looking for. That would be a really nice feature.

Thanks for the reply. I will give this a go tomorrow.

@jnm2
Copy link
Contributor

jnm2 commented Jan 20, 2018

@CharliePoole What do you think of allowing ValueSource on each param of a fixture constructor? It sounds like that would solve the problem. It seems more consistent with test methods.

@CharliePoole
Copy link
Contributor

@jnm2 My first reaction was "We have an issue for that!" but I can't find one. 😞

We had lots of discussion of this in the past. We were going to implement parameterized fixtures in three stages: (1) like TestCase, (2) like TestCaseSource and (3) like Values, Random, etc. together with the various combining strategies.

As far as I can see, the issues were all closed after we did (1) and (2) and we just stopped tracking (3).

I'm not sure how or if that would solve the current issue but I think it's a feature we should have and is worth its own issue.

@jnm2
Copy link
Contributor

jnm2 commented Jan 20, 2018

Opened #2673 to track my suggestion.

@mitchellmaler, do you think the ability to put [ValueSource] on each constructor parameter would get you where you wanted to be, one parameter for the browser to test and the other parameter for the URL to test?

@rprouse
Copy link
Member

rprouse commented May 18, 2020

I am closing old uncategorized issues that have not had comments or made progress in several years. If anyone comes back with a compelling argument for these issues, we can reopen.

@rprouse rprouse closed this as completed May 18, 2020
@rprouse rprouse added this to the Closed Without Action milestone May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants