Skip to content

Nsidorenco/neotest-vstest

Repository files navigation

GitHub release (latest SemVer) LuaRocks Package

test discovery sample

Neotest VSTest

Neotest adapter for dotnet

  • Based on the VSTest for dotnet allowing test functionality similar to those found in IDEs like Rider and Visual Studio.
  • Supports all testing frameworks.
  • DAP strategy for attaching debug adapter to test execution.
  • Supports C# and F#.
  • No external dependencies, only the dotnet sdk required.
  • Can run tests on many groupings including:
    • All tests
    • Test projects
    • Test files
    • Test all methods in class
    • Test individual cases of parameterized tests

Pre-requisites

neotest-vstest makes a number of assumptions about your environment:

  1. The dotnet sdk, and the dotnet cli executable in the users runtime path.
  2. (For Debugging) netcoredbg is installed and nvim-dap plugin has been configured for netcoredbg (see debug config for more details)
  3. (recommended) treesitter parser for either C# or F# allowing run test in file functionality.
  4. neovim v0.10.0 or later

Installation

{
  "nsidorenco/neotest-vstest"
}

Usage

require("neotest").setup({
  adapters = {
    require("neotest-vstest")
  }
})

The adapter optionally supports extra settings:

-- NOTE: This should be set before calling require("neotest-vstest")
vim.g.neotest_vstest = {
  -- Path to dotnet sdk path.
  -- Used in cases where the sdk path cannot be auto discovered.
  sdk_path = "/usr/local/dotnet/sdk/9.0.101/",
  -- table is passed directly to DAP when debugging tests.
  dap_settings = {
    type = "netcoredbg",
  },
  -- If multiple solutions exists the adapter will ask you to choose one.
  -- If you have a different heuristic for choosing a solution you can provide a function here.
  solution_selector = function(solutions)
    return nil -- return the solution you want to use or nil to let the adapter choose.
  end,
  -- If multiple .runsettings/testconfig.json files are present in the test project directory
  -- you will be given the choice of file to use when setting up the adapter.
  -- Or you can provide a function here
  -- default nil to select from all files in project directory
  settings_selector = function(project_dir)
    return nil -- return the .runsettings/testconfig.json file you want to use or let the adapter choose
  end,
  build_opts = {
      -- Arguments that will be added to all `dotnet build` and `dotnet msbuild` commands
      additional_args = {}
  },
  timeout_ms = 30 * 5 * 1000 -- number of milliseconds to wait before timeout while communicating with adapter client
}

require("neotest").setup({
  adapters = {
    require("neotest-vstest")
  }
})

Debugging adapter

  • Install netcoredbg to a location of your choosing and configure nvim-dap to point to the correct path

This adapter uses that standard dap strategy in neotest. Run it like so:

  • lua require("neotest").run.run({strategy = "dap"})

Acknowledgements

Contributors 10

Languages