Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch Console running all tests in sln when given a child csproj arg
Grendil
#1 Posted : Wednesday, August 23, 2017 9:01:20 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/18/2017(UTC)
Posts: 54
Location: United States of America

Thanks: 22 times
Was thanked: 11 time(s) in 10 post(s)
My understanding had been that passing a csproj file as the target argument to NCrunch console exe would tell NCrunch to only run tests in that project. I believe I've seen this behavior work as expected too, however very recently I'm seeing it instead target the entire solution.
Is this because the project is in a subfolder of a a solution that has an ncrunchsolution file that includes a custom engine mode definition?

Code:
<SolutionConfiguration>
  ...
  <EngineModes>
    <EngineMode>
      <Name>Continuous Testing</Name>
      <Settings>
        <TestsToExecuteAutomatically>(HasCategory 'ContinuousTesting' AND IsImpacted)</TestsToExecuteAutomatically>
      </Settings>
    </EngineMode>
  </EngineModes>


If that parent solution setting overrides the fact that our command line targets a specific project, what do we do to correctly target just the project?
Remco
#2 Posted : Wednesday, August 23, 2017 11:36:59 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
NCrunch itself doesn't contain any logic to automatically find and load a parent solution for a targeted project. When you run the console tool against a .proj file, NCrunch will create a virtual solution internally using default settings and will load the targeted project into memory, along with all other projects that it depends on.

Assuming this is a test project (which for useful purposes it would likely need to be), it will have dependencies on other projects in its area. NCrunch will load those dependencies and include them in the virtual solution, along with all of their dependencies. So probably you'll end up with a very large slice of your solution being loaded and processed.

Processing dependencies is necessary because NCrunch is a pre-build tool that works from your source code, not from compiled artifacts. This means it needs to load and build every dependency itself.
1 user thanked Remco for this useful post.
Grendil on 8/23/2017(UTC)
Grendil
#3 Posted : Wednesday, August 23, 2017 11:53:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/18/2017(UTC)
Posts: 54
Location: United States of America

Thanks: 22 times
Was thanked: 11 time(s) in 10 post(s)
Remco;11044 wrote:
NCrunch itself doesn't contain any logic to automatically find and load a parent solution for a targeted project. When you run the console tool against a .proj file, NCrunch will create a virtual solution internally using default settings and will load the targeted project into memory, along with all other projects that it depends on.

Assuming this is a test project (which for useful purposes it would likely need to be), it will have dependencies on other projects in its area. NCrunch will load those dependencies and include them in the virtual solution, along with all of their dependencies. So probably you'll end up with a very large slice of your solution being loaded and processed.

Processing dependencies is necessary because NCrunch is a pre-build tool that works from your source code, not from compiled artifacts. This means it needs to load and build every dependency itself.


OK, got it, that makes sense, and I see now a surprising dependency on other test projects from the one I targeted.

What is the easiest way to have the command line target just one project itself and not its dependent brethren? We're trying to set up a build server to run separate jobs for different test projects, even if they have some mudball relations between them.
Remco
#4 Posted : Thursday, August 24, 2017 12:25:40 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Grendil;11046 wrote:

What is the easiest way to have the command line target just one project itself and not its dependent brethren? We're trying to set up a build server to run separate jobs for different test projects, even if they have some mudball relations between them.


In terms of build execution, this can only be achieved by restructuring your solution so that there are no build dependencies between your projects. You could do this by replacing ProjectReferences with AssemblyReferences. In this way, NCrunch will treat the referenced projects as being simple binaries rather than projects that need to be compiled and processed. I can suggest no way of doing this that won't involve gutting your projects and making them difficult to work on outside the build system.

In terms of test execution, this would be done using the TestsToExecuteAutomatically filter, either as an engine mode or injected into the tool through the command line. The filter has a condition that can be used to run tests only within a specific namespace. Or alternatively, you could apply a category to the tests at assembly level using NCrunch.Framework.CategoryAttribute inside AssemblyInfo.cs, then use the category condition on the filter.


1 user thanked Remco for this useful post.
Grendil on 8/24/2017(UTC)
Grendil
#5 Posted : Thursday, August 24, 2017 4:47:49 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/18/2017(UTC)
Posts: 54
Location: United States of America

Thanks: 22 times
Was thanked: 11 time(s) in 10 post(s)
Remco;11049 wrote:
Grendil;11046 wrote:

What is the easiest way to have the command line target just one project itself and not its dependent brethren? We're trying to set up a build server to run separate jobs for different test projects, even if they have some mudball relations between them.


In terms of build execution, this can only be achieved by restructuring your solution so that there are no build dependencies between your projects. You could do this by replacing ProjectReferences with AssemblyReferences. In this way, NCrunch will treat the referenced projects as being simple binaries rather than projects that need to be compiled and processed. I can suggest no way of doing this that won't involve gutting your projects and making them difficult to work on outside the build system.

In terms of test execution, this would be done using the TestsToExecuteAutomatically filter, either as an engine mode or injected into the tool through the command line. The filter has a condition that can be used to run tests only within a specific namespace. Or alternatively, you could apply a category to the tests at assembly level using NCrunch.Framework.CategoryAttribute inside AssemblyInfo.cs, then use the category condition on the filter.




I've got it now, thanks for clearing me up. I'm using TestsToExecuteAutomatically in the command line with IsInProjectWithName to make sure I've got just the test project I want for that build job. Looks like it's working great thanks.
1 user thanked Grendil for this useful post.
Remco on 8/24/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download