dotnet-watch
on a project as described “Develop ASP.NET Core apps using a file watcher”, and specifically the section Run tests using dotnet watch
, does not detect additions of new file.
Create a directory for the project:
mkdir DotNetWatcherIssueDemo
Change to the project directory:
cd DotNetWatcherIssueDemo
Initialize it with a new test project:
dotnet new nunit
Launch VS Code on the directory containing the test project:
code .
Ask to watch project and run tests on changes:
dotnet watch test
At this stage, you should see the output:
watch : Started
Build started, please wait...
Build completed.
Test run for A:\temp\DotNetWatchIssueDemo\bin\Debug\netcoreapp2.2\DotNetWatchIssueDemo.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.9364 Seconds
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
Now add a new test to UnitTest1.cs
:
diff --git a/UnitTest1.cs b/UnitTest1.cs
index 66ec70e..f6406e7 100644
--- a/UnitTest1.cs
+++ b/UnitTest1.cs
@@ -14,5 +14,11 @@ namespace Tests
{
Assert.Pass();
}
+
+ [Test]
+ public void Test2()
+ {
+ Assert.Pass();
+ }
}
}
\ No newline at end of file
dotnet watch
will pick up the change, run _two_ tests successfully and continue to watch for further file changes:
watch : Started
Build started, please wait...
Build completed.
Test run for A:\temp\DotNetWatchIssueDemo\bin\Debug\netcoreapp2.2\DotNetWatchIssueDemo.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Total tests: 2. Passed: 2. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.9698 Seconds
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
In a separate shell, cd
into the project directory and add a new test file:
dotnet new nunit-test -n UnitTest2 -o .
At the last step, I expected dotnet watch
to pick up the new file change, build and re-run all tests, but it does nothing.
It seems that it builds a static list of files and only watches those for changes. If I touch/force-save the project file (DotNetWatcherIssueDemo.csproj
) then dotnet watch
detects the change, re-builds the watch list and detects changes to the added file, but again, not for any new file added thereafter.
Output of dotnet --info
:
.NET Core SDK (reflecting any global.json):
Version: 2.2.101
Commit: 236713b0b7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.101\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
1.1.8 [C:\Program Files\dotnet\sdk]
1.1.9 [C:\Program Files\dotnet\sdk]
1.1.10 [C:\Program Files\dotnet\sdk]
1.1.11 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
/cc @natemcmaster
Based on the following comment in the code, this is clearly a bug and lacking:
I say a bug because if it's a limitation then it's not documented anywhere.
Any progress on this?
+1 for this.
I've got a pretty sweet workflow setup with Verify, allowing me just iterate on tests, approve outputs and have the tests re-run. The only part lacking is when I want to expand my test suite with new files.
A workaround is to keep adding test classes into the same file and then split them out later, but it's a bit painful. Edit: Not so bad with the quick refactoring to move the class out to a new file when you're knocking them out later.
Most helpful comment
Based on the following comment in the code, this is clearly a bug and lacking:
https://github.com/aspnet/AspNetCore/blob/1f050242559e7b90ff6c4ee7f99d92b3a5af5a62/src/Tools/dotnet-watch/src/Internal/MsBuildFileSetFactory.cs#L66-L67
I say a bug because if it's a limitation then it's not documented anywhere.