XUnit project can't reference project referenced by the project it's testing

150 views Asked by At

I'm creating a project I've named Amino which builds on the Monogame/XNA C# game framework.

I've also created an XUnit test for Amino, called Amino.UnitTest.

In the unit test, I'm able to interact with classes from Amino, but not classes from XNA. This is a problem because I need to deal with Vector2s and other things that XNA defines.

// "The type or namespace Xna does not exist"
using Microsoft.Xna.Framework;
using Xunit;

namespace Amino.UnitTest
{
    public class MatrixTests
    {
        [Fact]
        public void SimpleTest()
        {
            Matrix3x3 m = new Matrix3x3();
            // "Vector2 is defined in an assembly that is not referenced."
            Vector2 v = m.Up;
        }
    }
}

My project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.2.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Amino\Amino.csproj" />
  </ItemGroup>

</Project>

The structure of the solution is:

Solution.sln
-- Amino.csproj
-- Amino.UnitTest.csproj
-- GameThatUsesAmino.csproj
0

There are 0 answers