-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Installed Product Versions
- Visual Studio: 2019 Professional
- This extension: 2.6.1
Description
The following token would be another nice addition to your main content section.
The particular use case I'm working with involves mimicking existing SUT functionality in an API level Constructor for our Business Level Tests. The constructor calls a function in the Business Level Base class. This Business Level function, if called, changes the default behavior of several of our MUTs (Methods Under Test). But we have to remember to call it EVERY time we generate a new Test class.
The complexity comes in the fact that this function automatically calls another function in the Database Level Base Interface, which is the base interface of every single Database interface that we have to mock. We are also using Strict detection, so the Database function will have to have to have an arrangement set up for it before the SUT's method is called. We know that each interface will be the first one that the UTBG picks up, but it will be one that is only known at generation time. We cannot merely name the base Interface and arrange it. We have to know the name of the mock object at code generation time.
This single new token would give us the flexibility we need to set up the template to automatically set up this call as part of the SUT initialization:
| Scope | Token | Description | Example |
|---|---|---|---|
| Main Content | The name of a generated mock field token where <n> is the field index of the token. Also usable in the Test Method Invoke/Empty templates. |
mockChildInterface.baseClassFunction(); |
|
| Main Content | $MockField <InterfaceOrClassName>$ |
The name of a generated mock field token where InterfaceOrClassName is the Class Name, a Base Class it inherits, or an Interface/Base Interface it implements. Also usable in the Test Method Invoke/Empty templates. |
.baseFunction(); -> mockChildInterface.baseFunction(); |
| Mock Field Formats | The generated name for the mock object. Specified by "Mock object reference format" field. |
mockChildInterface.Object |