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
89 stars 20 forks source link

I want to change the text in Assert.Fail #226

Closed shshshshgoodnj closed 1 year ago

shshshshgoodnj commented 1 year ago

The code I want to fix in Framework Generation.feature

        [NUnit.Framework.TestAttribute()]
        [NUnit.Framework.DescriptionAttribute("Framework Generation Test - AssertFail")]
        [NUnit.Framework.TestCaseAttribute("MsTest", "Assert.Fail(\"Create or modify test\");", null)]
        [NUnit.Framework.TestCaseAttribute("NUnit3", "Assert.Fail(\"Create or modify test\");", null)]
        [NUnit.Framework.TestCaseAttribute("XUnit", "throw new NotImplementedException(\"Create or modify test\");", null)]
        public virtual void FrameworkGenerationTest_AssertFail(string framework, string statement, string[] exampleTags)
        {
            string[] tagsOfScenario = exampleTags;
            System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary();
            argumentsOfScenario.Add("framework", framework);
            argumentsOfScenario.Add("statement", statement);
            TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Framework Generation Test - AssertFail", null, tagsOfScenario, argumentsOfScenario, this._featureTags);

I want to replace the text that is "Asert.Fail(\"Create or modify test\" with "Asert.Fail("Fail") in '[NUnit.Framework.TestCaseAttribute("MsTest", "Assert.Fail(\"Create or modify test\");", null)]'

However, even if I modify the code, it will go back to "Asert.Fail(\"Create or modify test\" How do I prevent my modified code from being go back even if I build it?


This is the result I want when I do the unit test through the code I modified.

Before, Modify

        [TestMethod]
        public void CanCallGetDataTest()
        {
            // Arrange
            var roiData = _fixture.Create<Info>();

            // Act
            _testClass.GetData(roiData, out var refData, out var refDiffData);

            // Assert
            Assert.Fail("Create or modify test");
        }

After, Modify

 [TestMethod]
        public void CanCallGetDataTest()
        {
            // Arrange
            var roiData = _fixture.Create<Info>();

            // Act
            _testClass.GetData(roiData, out var refData, out var refDiffData);

            // Assert
            Assert.Fail("Fail");
        }
mattwhitfield commented 1 year ago

That's not configurable yet, I'll add something 👍

mattwhitfield commented 1 year ago

This should be available in 0.195 💥 Under 'Generation Options' there is 'Default failure message' which you can configure as you please. Please let me know if it works for you