Testing custom StyleCop rules: Call to AddSourceFile() always returns false when using ReSharper testrunner

StackOverflow https://stackoverflow.com/questions/20990742

Domanda

I asked this question in the StyleCop forum but never got an answer.


I found lots of examples for testing custom rules using MSTest and I got that one to work easily enough.

But these tests don't work when using the ReSharper testrunner. For some reason the call to

StyleCopConsole.Core.Environment.AddSourceFile(...)

always returns false whenever I use something other than VS 2010's built-in testrunner via the Test View. As that Test View is possibly the least user-friendly tool I ever had to use for running tests I would prefer to use ReSharper. A lot.

I have a sub-folder inside my test assembly called Resources which contains the invalid source files for my tests and the Settings.StyleCop file. They are copied to the test output folder correctly (I added an extra check using File.Exists prior to calling AddSourceFile(...) to make sure of that).

I added references to StyleCop.dll, StyleCop.CSharp.dll and StyleCop.CSharp.Rules.dll which did not solve the problem.

Using the ReSharper runner the StyleCopCore.Parsers collection is always empty. When I use the VS runner it contains a CsParser.

Any ideas what I'm missing?

È stato utile?

Soluzione

The StyleCopConsole.Core.Environment expects that you've registered a parser for the file extension you're feeding to it. So you probably want to add a CsParser instance to the Parsers collection and set the extension to .cs.

Luckily the sources for StyleCop are available so it pays off to check why a code path might return false and see whether that precondition has been passed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top