✅ What is the standard way of doing tests? (and can I exclude tests from a library build?)
I was going to ask one question, but as I was told yesterday that I'm not following C# convention, I'm going to start by asking what the convention is for this!
What is the standard convention for doing tests on a library? (I'm using NUnit)
The way I've set it up so far is to have a "Tests" folder in the project, and running
dotnet test
is working well for that.
However, I'm finding that the resulting .dll when I build the library includes the test classes, which I would like to avoid.
Should I be doing the tests in a different way?
Alternatively, when I call dotnet build
, is there a way to tell it to exclude a folder so that it doesn't build the tests into the release?
Thanks22 Replies
the convention is to make a separate project for tests, or even for each project you want to test
if you want to test internal things, you can use
AssemblyVisibleTo
ah - okay - thanks - that's good to know
So would it normally be structed as a single repository with 2 projects in?
yes
got it - thanks 🙂
np
And then in VSCode, my tasks.json could point at different project files for test and build
Thanks - appreciate it
yeah you'd need 2 tasks
With a .csproj file, is it possible to have each one specify which folders to reference?
yes, but people usually don't do it
I'd love to keep both .csproj files in the root of the project, and have one look at the "Tests" folder, and the other at the "MyLib" folder
ok
so separate folders per project?
yes
Side question, then - do you know how, in vscode, I can tell the "test" task that it needs to run the "build" task first (to build the library)?
well there are tasks and there is the launch.json
testing should probably go into launch
Ah - good point, as there's no executable to launch
But if you have multiple tasks and want to maintain them in the source control, vs code tasks are pretty fragile
you move a folder or change the output directory and it will stop working
Right
for larger projects use rider
there is the test dll
I meant for the library itself
Yeah - I want to look at Rider
I've used Rider for Unreal (for C++) a lot in the past, and really like it
executable and library are basically the same thing
okay. But the MyLib.dll doesn't have a Main in, so there's no point in launching it directly
There we go. I've got my projects split out now
it's going to be loaded from the test dll
yes