reqnroll / Reqnroll

Open-source Cucumber-style BDD test automation framework for .NET.
https://reqnroll.net
BSD 3-Clause "New" or "Revised" License
302 stars 33 forks source link

Features are not found by ReqnrollFeatureFiles/ReqnrollGeneratedFiles when the feature files are in a shared project that is referenced by Content Include in csproj #188

Closed maurictg closed 2 weeks ago

maurictg commented 2 weeks ago

Reqnroll Version

2.0.3

Which test runner are you using?

NUnit

Test Runner Version Number

4.1.0

.NET Implementation

.NET 8.0

Test Execution Method

ReSharper Test Runner

Content of reqnroll.json configuration file

{ "$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json", "language": { "feature": "en-US" } }

Issue Description

We are using Appium for UI testing our app. We need a seperate project for Android and for iOS.
The shared project has the following csproj:

<Project Sdk="Microsoft.Build.NoTargets/3.7">
    <PropertyGroup>
        <TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net8.0</TargetFramework>
        <TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
        <GenerateAssemblyInfo>False</GenerateAssemblyInfo>
        <GenerateMSBuildEditorConfigFile>False</GenerateMSBuildEditorConfigFile>
        <GenerateTargetFrameworkAttribute>False</GenerateTargetFrameworkAttribute>
        <RootNamespace>App.UiTests.Shared</RootNamespace>
    </PropertyGroup>
    <ItemGroup>
        <None Include="Features\**\*.feature" />
        <Compile Include="**\*.cs" />
        <None Include="**\*.json" />
        <None Remove="obj\**\*" />
        <None Remove="bin\**\*" />
    </ItemGroup>
    <ItemGroup>
        <None Update="appsettings.json">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
    </ItemGroup>
</Project>

It is a NoTargets project, so this project won't be compiled. The C# and Feature files are referenced into the other assemblies with the following csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <IsPackable>false</IsPackable>
        <IsTestProject>true</IsTestProject>
        <RootNamespace>App.UiTests.Android</RootNamespace>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Appium.WebDriver" Version="5.0.0" />
        <PackageReference Include="coverlet.collector" Version="6.0.2">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
        <PackageReference Include="NUnit" Version="4.1.0" />
        <PackageReference Include="NUnit.Analyzers" Version="4.2.0">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
        <PackageReference Include="Reqnroll.NUnit" Version="2.0.3" />
        <PackageReference Include="Reqnroll.Tools.MsBuild.Generation" Version="2.0.3" />
        <PackageReference Include="Shouldly" Version="4.2.1" />
    </ItemGroup>
    <ItemGroup>
        <Using Include="NUnit.Framework" />
    </ItemGroup>
    <ItemGroup>
        <Content Include="..\App.UiTests.Shared\Features\**\*.feature"
                 Link="Features\%(RecursiveDir)%(Filename)%(Extension)"
                 CopyToOutputDirectory="PreserveNewest" />

        <None Include="..\App.UiTests.Shared\*.json"
              Link="%(Filename)%(Extension)"
              CopyToOutputDirectory="PreserveNewest" />

        <Compile Include="..\App.UiTests.Shared\**\*.cs"
                 Link="Shared\%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>
    <ItemGroup>
        <Content Include="Features\*.feature" />
    </ItemGroup>
</Project>

If I add normal unit tests to the shared project, they can be run when running the Android or iOS project. However, ReqNRoll does not "see" the .feature files nor compiles them.

Can you help us out? I want to avoid real symlinking, and want to just include the files to the Android/iOS project.

Steps to Reproduce

  1. Create a shared project with the first CSPROJ from the issue description. Add a folder "Features" with one .feature file in it, with one scenario. Also add a folder "Steps" and add one step implementation to that feature file in it.
  2. Create two NUnit test projects with the second CSPROJ from the issue description. If you are using an IDE like rider, two folders will show up: Features and Shared (with the Steps folder in Shared)
  3. Build one of the NUnit projects
  4. Notice that the feature file is not compiled
  5. Open the test runner and notice that the feature is missing

Also, the output is not listing the features:

0>------- Started building project: App.UiTests.Android
ReqnrollFeatureFiles: 
-> Using reqnroll.json
ReqnrollGeneratedFiles: 

Link to Repro Project

https://github.com/maurictg/repro-reqnroll-sharedprojects

maurictg commented 2 weeks ago

It seems to be a Rider issue. dotnet build in the Android/iOS folder followed by dotnet test works just fine.

ajeckmans commented 2 weeks ago

If it is a rider issue it most likely had to do with the resharper build engine and their heuristics to determine a particular project is up to date. If you manually include files in a nocontent project you will have to specify the uptodatecheckinput https://github.com/dotnet/project-system/blob/main/docs/up-to-date-check.md