Neotest adapter for dotnet tests
NOTE - This is a WIP project and will be under development over the coming months with additional features
- Please feel free to open an issue
neotest-dotnet requires makes a number of assumptions about your environment:
- The
dotnet sdk
that is compatible with the current project is installed and thedotnet
executable is on the users runtime path (future updates may allow customisation of the dotnet exe location) - The user is running tests using one of the supported test runners / frameworks (see support grid)
- (For Debugging)
netcoredbg
is installed andnvim-dap
plugin has been configured fornetcoredbg
(see debug config for more details) - Requires nvim-treesitter and the parser for C#.
use({
"nvim-neotest/neotest",
requires = {
{
"Issafalcon/neotest-dotnet",
},
}
})
Plug 'https://github.com/nvim-neotest/neotest'
Plug 'https://github.com/Issafalcon/neotest-dotnet'
require("neotest").setup({
adapters = {
require("neotest-dotnet")
}
})
Additional configuration settings can be provided:
require("neotest").setup({
adapters = {
require("neotest-dotnet")({
-- Extra arguments for nvim-dap configuration
-- See https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for values
dap = { justMyCode = false },
-- Let the test-discovery know about your custom attributes (otherwise tests with not be picked up)
-- Note: Only custom attributes for non-parameterized tests should be added here. See the support note about parameterized tests
custom_attributes = {
xunit = { "MyCustomFactAttribute" },
nunit = { "MyCustomTestAttribute" },
mstest = { "MyCustomTestMethodAttribute" }
}
})
}
})
Screencast.from.10-23-2022.01.40.06.PM.webm
- Install
netcoredbg
to a location of your choosing and configurenvim-dap
to point to the correct path - The example below uses the
mason.nvim
default install path:
local install_dir = path.concat{ vim.fn.stdpath "data", "mason" }
dap.adapters.netcoredbg = {
type = 'executable',
command = install_dir .. '/packages/netcoredbg/netcoredbg',
args = {'--interpreter=vscode'}
}
NOTE: When debugging, the result output is currently not correctly relayed back to neotest (it instead reads the output from the debugger process, and registers all tests run using the 'dap' strategy as failed). The correct test feedback is displayed in a terminal window as a workaround for this limitation. This will also affect the output in the neotest-summary window. Hopefully this will be fixed in time.
✔️ = Fully supported
〽️ = Partially Supported (functionality might behave unusually)
❌ = Unsupported (tested)
Runner / Framework | Unit Tests | *Parameterized Unit Tests (e.g. Using TestCase attribute) |
Specflow | Debugging |
---|---|---|---|---|
C# - NUnit | ✔️ | ✔️ | ✔️ | ✔️ |
C# - XUnit | ✔️ | ✔️ | 〽️ (issues with test name linking) | ✔️ |
C# - MSTest | ✔️ | ✔️ | ✔️ | ✔️ |
F# - NUnit | ||||
F# - XUnit | ||||
F# - MSTest |
- Parameterized tests are only itemized by the adapter when the attribute arguments are inline values. For any parameterized test attributes (including custom ones) that take non-inlined values the adapter will lump all these tests together in one.
- A tradeoff was made between being able to run parameterized tests and the specificity of the
dotnet --filter
command options. A more lenient 'contains' type filter is used in order for the adapter to be able to work with parameterized tests. Unfortunately, no amount of formatting would support specificFullyQualifiedName
filters for the dotnet test command for parameterized tests. - See the support guidance for feature and language support
- F# is currently unsupported due to the fact there is no complete tree-sitter parser for F# available as yet (https://github.com/baronfel/tree-sitter-fsharp)
- As mentioned in the Debugging section, there are some discrepancies in test output at the moment.