Setting Up a .NET Solution with xUnit Test Project
Step 1 – Create the Test Project
dotnet new xunit -n BuffetConnect.E2E -f net10.0
Purpose: Creates a new xUnit test project.
-n BuffetConnect.E2E: Names the project folder and.csprojfile.-f net10.0: Targets .NET 10 framework.
Result: Generates BuffetConnect.E2E/ folder containing BuffetConnect.E2E.csproj, UnitTest1.cs, and obj/.
Note: This is the project where you will write your tests.
Step 2 – Navigate to the Parent Directory
cd ~/Desktop/project/automation/buffet-automation
Purpose: Ensure that the solution file will be created in the correct directory.
Why: The solution file should be one level above the projects it contains.
Step 3 – Create the Solution File
dotnet new sln -n BuffetConnect
Purpose: Creates a solution file BuffetConnect.sln.
Why: The solution is a container for multiple projects (your tests, main app, libraries).
Result: You now have a .sln file ready to hold one or more projects.
Important: Do not try to add projects before creating the solution.
Step 4 – Add the Test Project to the Solution
dotnet sln add BuffetConnect.E2E/BuffetConnect.E2E.csproj
Purpose: Adds the test project to the solution.
Why: The solution now “knows” about this project, so you can build, test, or run everything from the solution level.
Tip: Run this from the directory where the
.slnfile exists.
Step 5 – Verify Projects in the Solution
dotnet sln list
Purpose: Confirms which projects are included in the solution.
Expected Output:
Project(s)
----------
BuffetConnect.E2E/BuffetConnect.E2E.csproj
Directory Structure After Setup
buffet-automation/
├── BuffetConnect.sln <-- Solution container
└── BuffetConnect.E2E/ <-- Test project
├── BuffetConnect.E2E.csproj
├── UnitTest1.cs
└── obj/
Key Takeaways
- Always create the solution first, then add projects.
- Run solution commands (
dotnet sln add,dotnet sln list) from the solution folder, not the project folder. - Keep solution at top level, projects in subfolders — this scales well for multiple projects.
- Your
.csprojcontains the actual code/tests; the.slnjust manages projects together.
Written by A.M. Rinas