C
C#3w ago
Bubba

Issue installing NUnit

Hello, I have been trying to install NUnit to add unit tests to my main project. To do so, I created a new project on Rider. The file structure is the following: \ \MainProject.sln \MainProject.csproj \TestProject\TestProject.csproj MainProject.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.67" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.67" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>
</Project>
12 Replies
Bubba
Bubba3w ago
TestProject.csproj:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>

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

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

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

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

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>

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

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

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

</Project>
When trying to start the tests using dotnet test, I get the following error:
Project/Project.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'SetUpAttribute' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'SetUp' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(10,6): error CS0246: The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(10,6): error CS0246: The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'SetUpAttribute' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'SetUp' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(10,6): error CS0246: The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Project/Project.Tests/UnitTest1.cs(10,6): error CS0246: The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?) [Project/Browser.csproj]
Already tried to clean the nuget cache using dotnet nuget locals all --clear and doing dotnet clean but it does not change anything
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Bubba
Bubba3w ago
Yup, I kept the default test
using NUnit.Framework;

namespace Browser.Tests;

public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Test1()
{
Assert.Pass();
}
}
using NUnit.Framework;

namespace Browser.Tests;

public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Test1()
{
Assert.Pass();
}
}
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Bubba
Bubba3w ago
same issue :/
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Bubba
Bubba3w ago
Determining projects to restore...
Restored Project/Project.Tests/Project.Tests.csproj (in 128 ms).
Restored Project/Project.csproj (in 128 ms).
Determining projects to restore...
Restored Project/Project.Tests/Project.Tests.csproj (in 128 ms).
Restored Project/Project.csproj (in 128 ms).
Not sure if it can cause a problem, but the main project is at the root of the repository, not in a subfolder
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Bubba
Bubba3w ago
i'll send you in pm, one sec
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Bubba
Bubba3w ago
then we'll have to do without it
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server