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

Customize TestMethods template #42

Closed MilesLin closed 5 years ago

MilesLin commented 5 years ago

Installed product versions

Description

I'm using xUnit and NSubstitute to create unit tests. Is possible to define my own $TestMethods$ variable?

Current behavior

Current TestMethods will generate the code below. It always compiles failed on TODO and Assert.Fail(), it kind of annoying for me

        [Fact]
        public void Post_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateValuesController();
            string value = TODO;

            // Act
            unitUnderTest.Post(
                value);

            // Assert
            Assert.Fail();
        }

Expected behavior

I will expect to generate the code below. No compile error.

        [Fact]
        public void Post_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateValuesController();
            string value = "";

            // Act
            unitUnderTest.Post(
                value);

            // Assert
            Assert.True(false, "Not Implement");
        }

Miles regards.

RandomEngy commented 5 years ago

In 1.9.13 I changed it to use Assert.True(false) for xUnit, so it compiles.

It still inserts TODO for variables; but that is by design. I like to ensure that the value of every variable is considered and eliminate the possibility that some are just left as default because they were neglected (rather that being the correct value to test with). It also puts a big red flag where attention is needed.