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

Failing to generate unit test for structs #49

Closed OJacot-Descombes closed 4 years ago

OJacot-Descombes commented 4 years ago

Installed product versions

Description

Throws exception "InvalidOperationException: Could not find class declaration." when trying to generate unit test for a struct. I assume this is a current limitation. In this case consider this to be a feature request.

Steps to recreate

  1. Create as *.cs file containing only a struct.
  2. Right click in solution explorer and select "Create Unit Test Boilerplate..."
  3. Select Test Framework: VisualStudio
  4. Select Mock Framework: NSubstitute
  5. Click button "Create Unit Test Class"

Current behavior

Throws exception "InvalidOperationException: Could not find class declaration."

Expected behavior

Should generate unit test.

RandomEngy commented 4 years ago

What kind of unit tests would you write for a struct?

OJacot-Descombes commented 4 years ago

Structs can have constructors and methods (in my specific case a Deconstructor). So, why not test them as I would for a class? Think of the System.Drawing.Rectangle struct. It has quite a complex implementation.

RandomEngy commented 4 years ago

So they do. I had always used classes when needing methods, etc. I'll look into it.

RandomEngy commented 4 years ago

Fixed in 2.3.0