microsoft / UnitTestBoilerplateGenerator

An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, Moq and SimpleStubs.
MIT License
158 stars 51 forks source link

Include option for No Mock Library #34

Closed drobertson123 closed 5 years ago

drobertson123 commented 6 years ago

Installed product versions

Description

Please add an option for using no Mock library. In many cases, we don't want a Mock layer in our testing. I do use mocks and appreciate them very much but mocks are not a one size fits all answer.

In many cases I want a simple test class constructed. A method for creating the object is great and a few support functions but otherwise just a basic class object would be wonderful.

Expected behavior

Right click on class and select "Create Unit Test Boilerplate..." Choose the appropriate test framework. In the Mock Framework drop-down there would be a selection of "None"

Create Unit Test would then create a test class using the appropriate template using No Mock library.

RandomEngy commented 6 years ago

So you'd just want it to make the test file and methods for all the public methods?

drobertson123 commented 6 years ago

Yes, basically.

The tools allow us to force consistency across the developers. It is a quick way to set up the test class in the right place and the right way. Ideally, I would like to be able to edit the template for the no mock option, but even a basic no frills option would be a huge help.

RandomEngy commented 6 years ago

I'll put that support on the backlog. For now you could edit the VisualStudio/Moq template and take out the parts you don't need. It will default to Moq when it can't detect any mocking framework.

drobertson123 commented 6 years ago

Sounds good. Thanks for responding on these.

sergedomk commented 5 years ago

Problem with this approach is that it makes it so you can't use boilerplate to render with Moq on a different project without changing the templates back again.

This is potentially an issue when your requirements for testing your organization's in-house code is different from that of 3rd party open source projects your organization contributes to.

However, it may be more useful to make the Mocking library option "Custom" rather than "None" as "None" implies no mocking and there is also a use-case for changing the parts to reflect other mocking libraries which aren't currently supported.

RandomEngy commented 5 years ago

Implemented ability to choose "None" for a mock framework in 1.10.5.

In the generated test methods it will have "TODO" for constructor parameters as it has no way to know how to fill them.