mattwhitfield / Unitverse

A unit test generation extension for Visual Studio that aims to always produce code that compiles - covering the basic cases automatically and preparing as much as it can for the complex cases.
MIT License
90 stars 20 forks source link

Unable to select the project to which the test will be added #66

Closed marbel82 closed 2 years ago

marbel82 commented 2 years ago

When I click "Generate test for method 'SomeMethod'..." I want to select project to which the test will be added, like is in NUnit Visual Studio Test Generator.

Some methods I test in the project with unit tests, and some methods I test with higher correlations (e.g. with database connection), than project has a different name.

Also, our project names have evolved over the years, so we have many patterns. Some projects I could refactor, but not all.

Do you have any ideas for my case?

mattwhitfield commented 2 years ago

So in order to control which test project is selected you can configure a .unitTestGeneratorConfig file, even on a per-solution basis if you want. So you could have something like TestProjectNaming={0}.SpongeBob (where {0} is the name of the source project). That should enable you to account for the many different patterns automatically.

I have tended to try and avoid the whole 'pop up a dialog box for each generation' as I find that really gets in the way of the flow. That being said - perhaps if you held down Control while clicking on the menu item it could show a configuration dialogue?

With the case for generating an integration test - what would you want to see? Obviously Unitverse sets up mocks etc - so I'd like to understand some more about what you would want there. I'd like to keep this issue about 'control which project a test is generated in' - would you mind opening another issue along with some detail of what you'd like to see for the integration tests and then I can think about whether it makes sense for Unitverse?

Thanks for the issue!

mattwhitfield commented 2 years ago

Another thought - I could potentially add a 'show configuration per generation' option which would have the values 'never', 'always' and 'when ctrl is pressed'.

Then you could configure it to behave how you wanted. I would probably show a dialog that let you select the target project from a drop down (and would remember the target project per source project for that VS session). I would also let you choose test/mock/assertion frameworks.

Would that work?

marbel82 commented 2 years ago

That's exactly the option I was thinking of - 'show configuration per generation'. You're right that the pop-up window is annoying, but sometimes it is necessary (would be useful).

I'm not sure if the solution of holding Ctrl will be convenient, but you can try it.

What would I like in this window? hmm
In NUnit Visual Studio Test Generator there was a combobox, but it was a little annoying to have to scroll and search for a project, because we have 12 test projects.

There could be a drop down, and it would be nice if it was a little higher after opening.


In my case .unitTestGeneratorConfig would be usefull if it could be configured per-project.

mattwhitfield commented 2 years ago

.unitTestGeneratorConfig would be usefull if it could be configured per-project.

I thought I might be able to do that quite simply - but it's actually not very easy.

So I will get on this - but it will take some time to get right.

mattwhitfield commented 2 years ago

I'm going to do this in two parts. I have written the code for the ability to have a .unitTestGeneratorConfig per-project, which lays some of the groundwork that would be needed for the dialog box. I need to do some more testing on it, but will release that first, then add the UI portion separately.

I'm considering whether it would be useful to be able to change all the options - so effectively having the dialog with 4 tabs (Target Project, Generation Options, Strategy Options, Naming Options). That way if you just want to change the target project, you just pick the target project and click OK. If you want to change other stuff, you can. Would appreciate your thoughts 👍

mattwhitfield commented 2 years ago

Per-project .unitTestGeneratorConfig now available in 0.105 👍

mattwhitfield commented 2 years ago

@marbel82 - Preview of the UI

For selecting projects: image

For controlling options (other two pages have a similar look): image

I have a bunch more to do on it, but just wanted to know if that looked like the right sort of thing

marbel82 commented 2 years ago

Cool! 👍

mattwhitfield commented 2 years ago

@marbel82 - The UI is available in 0.106 - there's a bunch of documentation about it on https://github.com/mattwhitfield/Unitverse/blob/master/docs/configuration.md

Short version - either go to Tools->Options->Unitverse->Generation Options and set 'Show user interface' to 'Always' or hold Control while you click on 'Generate tests...' You can also set UserInterfaceMode=Always in a .unitTestGeneratorConfig file for a particular project if you want.

Let me know what you think 👍

mattwhitfield commented 2 years ago

Closing for now - thanks for the issue ❤