1

I'm writing a curse word censorship system in C# using TDD and as I am fairly new to implementing TDD, I'm wondering if there's an alternative or better way to accomplish the task of ensuring a return string does not contain the curse words and variations on it. Due to this being a public forum, I am replacing the actual curse words in the code with clean words, so assume I am trying to censor the cleaner versions just for this post please:

[TestMethod]
        public void process_CensorCode_GivenJerkface_ReturnsStringWithoutJerkface()
        {
            //ACT
            string result = proc.process("Jerkface you Jerkfacing Jerkfacer &*E@*Jerkface391!!", PROCESS_CODE.CENSOR);
            //ASSERT
            Assert.IsFalse(result.Contains("Jerkface"));
        }

Obviously, my program also accounts for jerkface, jerKfAcE, jERKfaCe, etc.... and I want to test all of these. Do I need to write out a method for every single one of these variations in MSTest or is there some shortcut way to handle all of these variations in a single test? If you notice any other aspect of my test which could be improved, please also speak up. By the way, I have initialized with the following placed at the top of the TestClass:

[TestInitialize]
        public void Initialize()
        {
            //ARRANGE
            proc = new RegExProcessor();
        }
the_endian
  • 2,259
  • 1
  • 24
  • 49
  • 2
    Possible duplicate of [MSTest Equivalent for NUnit's Parameterized Tests?](http://stackoverflow.com/questions/2367033/mstest-equivalent-for-nunits-parameterized-tests) – jonrsharpe Dec 26 '16 at 10:47

1 Answers1

2

nUnit has TestCase attribute for this scenario. It could be used in the following way:

[Test]
[TestCase("Jerkface")]
[TestCase("jerKfAcE")]
//[TestCase("...")]
public void process_CensorCode_GivenJerkface_ReturnsStringWithoutJerkface(string checkedWord)
{
    //ACT
    string result = proc.process("Jerkface you Jerkfacing Jerkfacer &*E@*Jerkface391!!", PROCESS_CODE.CENSOR);
    //ASSERT
    Assert.IsFalse(result.Contains(checkedWord));
}

To achieve it with MSTest you should put more efforts because MSTest still does not support test cases in such simple form. This answer has details on how to complete it with MSTest.

Community
  • 1
  • 1
CodeFuller
  • 30,317
  • 3
  • 63
  • 79
  • It sounds like NUnit is the cleanest approach if it's a possibility, and it is... Have you gotten NUnit's adapter to work reliably with NUnit 3? I've had a few bugs in the past with it where the tests won't all run. – the_endian Dec 26 '16 at 11:33
  • Support of test cases is one of the reasons why I prefer NUnit over MSTest. As regards adapter - I'm using ReSharper test runner. – CodeFuller Dec 26 '16 at 12:01