I have just recently started using ReSharper and am looking for a way of resolving a particular issue I have with the "Type argument specification is redundant" tooltip/quickfix. When writing unit tests I have been using Assert.AreEqual<string>(x, y)
and ReSharper flags the usage of <string>
as redundant. I would like to not have that flagged as redundant for that or any similar usages in my unit tests. Is there any way to disable this particular usage case (which would be extensible to the other assertions)? Please note, I would like to avoid the suppress with comment because of the large amount of noise that would create in the source file. I also don't want to disable the feature entirely.
For clarification, the reason this particular case is incorrectly flagged in my opinion is because the usage of the generic causes the error of mismatched types in the assert to be flagged at compile time and not at test runtime. I would like to keep this fail early behavior but get rid of all the extra noise this causes in basically every test I write.
Thanks
Edit: There has been a question about what the test contents would look like so I'm providing an example of one such assertion that is causing ReSharper to flag the redundancy.
[TestMethod]
public void ViewModelConstructor_NullProgram_SetsVisibilityToCollapsed()
{
_currentProgram = null; //Set condition under test
var Target = TargetMaker(); //Use shared constructor code in all tests
Assert.AreEqual<System.Windows.Visibility>(System.Windows.Visibility.Collapsed, Target.SectionVisibility);
}
Edit 2: Here's an example of the before and after ReSharper's suggested change. These two pieces of code show very different results. I've noted the different behaviors in the test function names.
class ClassUnderTest
{
public string fieldUnderTest { get; set; }
public ClassUnderTest()
{
fieldUnderTest = "New Value";
}
}
[TestClass()]
public class ClassUnderTestTest
{
[TestMethod()]
public void ClassUnderTestConstructorTest_FailsTest()
{
ClassUnderTest target = new ClassUnderTest();
Assert.AreEqual(true, target.fieldUnderTest);
}
[TestMethod()]
public void ClassUnderTestConstructorTest_WontCompile()
{
ClassUnderTest target = new ClassUnderTest();
Assert.AreEqual<string>(true, target.fieldUnderTest);
}
}