Which RegEx's for MSpec?

Nov 13, 2013 at 8:20 AM
We've got a bit more complicated setup:

Project: Domain.First
Namespace: Domain.First
Sample class: Domain.First.SubNamespace.A

Project: Domain.Second
Namespace: Domain.Second
Sample class: Domain.Second.SubNamespace.B

Domain.IntegrationTests (contains all integration tests)
Namespce: Domain.IntegrationTests.Second
Sample spec class: Domain.IntegrationTests.Second.BSpec

Is it possible to create a TestCop regex for this?

Domain.Second.SubNamespace -> Domain.IntegrationTests.Second does not seem possible?!

(I also added MSpec's Subject attribute to the list of attributes)

Is it possible to deactivate the namespace regex and tell TestCop to just look for files with the same name and "Spec" added at the back in the whole solution?
Nov 14, 2013 at 7:45 PM
Edited Nov 14, 2013 at 7:48 PM
TestCop currently uses a RegEx to match Test assemblies to their correct Code assembly...assuming there is a 1 to 1 relationship.

In your codebase you have 2 code assemblies mapping to 1 test assembly...
 Domain.First  --> Domain.IntegrationTests
 Domain.Second --> Domain.IntegrationTests
You could write a RegEx to map the code to the test assembly but without taking into account the sub-namespace of the test class it wouldn't be possible to map across to the correct code assembly from the test. Test cop doesn't look at the namespace of the class to match the assemblies it looks at the root namespace of the assembly. I think the change you are requesting would be a reasonably big refactor.

Would it be possible for you split Domain.IntegrationTests into (Domain.First.IntegrationTests & Domain.Second.IntegrationTests) ? Or is there more complexity ?

Best Regards.
Dec 16, 2013 at 1:38 PM
I have a similar situation, except the project name of the class under test is used in the test class' namespace, ie. Domain.Tests.ProjectName.Name.Space.ClassNameTests. Some of the older code has Domain.Tests.ProjectNameTests.ClassNameTests.

Would it be possible to define a mask for the values extracted by the regex, fx. $1->projectname, $2->class namespace, $3-> classname. Mappings should include project name, project default namespace, assembly name (without suffix) and class namespace, the last of which should look in all artefacts produced by the solution.

Previously I have seen tests included in the project containing the tested classes, and excluded with compiler pragmas in the release version.

I think the main point is, that it would be useful to have a lot of flexibility in mapping test classes to classnames, as there is neither a one best way to structure test projects and there is a lot of legacy code, that can't just be refactored to suit expectations.

Best Regards,
Daniel Demus
Dec 16, 2013 at 7:21 PM
Currently TestCop expects a 1-1 mapping between each code assembly and test assembly.

I could make changes to support more complex regex pattern transformation if you are proposing a different way to match the test assembly to the code assembly? Can you give me some explicit examples?

Class: MyCorp.MyApp.DAL.Core.ClassName.cs
in the assembly: MyCorp.MyApp.DAL

would be tested by
Class: MyCorp.Tests.MyAppTests.DAL.Core.ClassNameTests.cs
in the assembly: MyCorp.Tests.MyAppTests.DAL

Aug 2, 2014 at 10:10 AM
Next release of TestCop will support a single test assembly for a solution...