|
| 1 | +<p align="center"> |
| 2 | +<a href="https://github.com/nsidorenco/neotest-vstest/releases"> |
| 3 | + <img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/nsidorenco/neotest-vstest?style=for-the-badge"> |
| 4 | +</a> |
| 5 | +<a href="https://luarocks.org/modules/nsidorenco/neotest-vstest"> |
| 6 | + <img alt="LuaRocks Package" src="https://img.shields.io/luarocks/v/nsidorenco/neotest-vstest?logo=lua&color=purple&style=for-the-badge"> |
| 7 | +</a> |
| 8 | +</p> |
| 9 | + |
| 10 | +# Neotest .NET |
| 11 | + |
| 12 | +Neotest adapter for dotnet tests |
| 13 | + |
| 14 | +- Integrates with the VSTest runner to support all testing frameworks. |
| 15 | +- DAP strategy for attaching debug adapter to test execution. |
| 16 | +- Supports both C# and F# projects. |
| 17 | +- Fine-grained test discovery and execution allowing running individual parameterized tests. |
| 18 | + |
| 19 | +# Pre-requisites |
| 20 | + |
| 21 | +neotest-vstest requires makes a number of assumptions about your environment: |
| 22 | + |
| 23 | +1. The `dotnet sdk`, and the `dotnet` cli executable in the users runtime path. |
| 24 | +2. (For Debugging) `netcoredbg` is installed and `nvim-dap` plugin has been configured for `netcoredbg` (see debug config for more details) |
| 25 | +3. Requires treesitter parser for either `C#` or `F#` |
| 26 | +4. `neovim v0.10.0` or later |
| 27 | + |
| 28 | +# Installation |
| 29 | + |
| 30 | +## [lazy.nvim](https://github.com/folke/lazy.nvim) |
| 31 | + |
| 32 | +``` |
| 33 | + use({ |
| 34 | + "nvim-neotest/neotest", |
| 35 | + requires = { |
| 36 | + { |
| 37 | + "nsidorenco/neotest-vstest", |
| 38 | + }, |
| 39 | + } |
| 40 | + }) |
| 41 | +``` |
| 42 | + |
| 43 | +# Usage |
| 44 | + |
| 45 | +```lua |
| 46 | +require("neotest").setup({ |
| 47 | + adapters = { |
| 48 | + require("neotest-vstest") |
| 49 | + } |
| 50 | +}) |
| 51 | +``` |
| 52 | + |
| 53 | +Additional configuration settings can be provided: |
| 54 | + |
| 55 | +```lua |
| 56 | +require("neotest").setup({ |
| 57 | + adapters = { |
| 58 | + require("neotest-vstest")({ |
| 59 | + -- Path to dotnet sdk path. |
| 60 | + -- Used in cases where the sdk path cannot be auto discovered. |
| 61 | + sdk_path = "/usr/local/dotnet/sdk/9.0.101/", |
| 62 | + -- table is passed directly to DAP when debugging tests. |
| 63 | + dap_settings = { |
| 64 | + adapter = "netcoredbg", |
| 65 | + } |
| 66 | + }) |
| 67 | + } |
| 68 | +}) |
| 69 | +``` |
| 70 | + |
| 71 | +# Debugging adapter |
| 72 | + |
| 73 | +[Debugging Using neotest dap strategy](https://user-images.githubusercontent.com/19861614/232598584-4d673050-989d-4a3e-ae67-8969821898ce.mp4) |
| 74 | + |
| 75 | +- Install `netcoredbg` to a location of your choosing and configure `nvim-dap` to point to the correct path |
| 76 | + |
| 77 | +This adapter uses that standard dap strategy in `neotest`. Run it like so: |
| 78 | + |
| 79 | +- `lua require("neotest").run.run({strategy = "dap"})` |
| 80 | + |
| 81 | +# Contributing |
| 82 | + |
| 83 | +Any help on this plugin would is much appreciated. |
| 84 | + |
| 85 | +## First steps |
| 86 | + |
| 87 | +If you have a use case that the adapter isn't quite able to cover, a more detailed understanding of why can be achieved by following these steps: |
| 88 | + |
| 89 | +1. Setting the `loglevel` property in your `neotest` setup config to `1` to reveal all the debug logs from neotest-vstest |
| 90 | +2. Open up your tests file and do what your normally do to run the tests |
| 91 | +3. Look through the neotest log files for logs prefixed with `neotest-vstest` (can be found by running the command `echo stdpath("log")`) |
| 92 | +4. You should be able to piece together how the nodes in the neotest summary window are created (Using logs from tests that are "Found") |
| 93 | + |
| 94 | +The general flow for test discovery and execution is as follows: |
| 95 | + |
| 96 | +1. Spawn VSTest instance at start-up. |
| 97 | +2. On test discovery: Send list of files to VSTest instance. |
| 98 | + - Once tests have been discovered the VSTest instance will write the discovered test cases to a file. |
| 99 | +3. Read result file and parse tests. |
| 100 | +4. Use treesitter to determine line ranges for test cases. |
| 101 | +5. On test execution: Send list of test ids to VSTest instance. |
| 102 | + - Once test results are in the VSTest instance will write the results to a file. |
| 103 | +6. Read test result file and parse results. |
| 104 | + |
| 105 | +## Running tests |
| 106 | + |
| 107 | +To run the tests from CLI, make sure that `luarocks` is installed and executable. |
| 108 | +Then, Run `luarocks test` from the project root. |
| 109 | + |
| 110 | +If you see a module 'busted.runner' not found error you need to update your `LUA_PATH`: |
| 111 | + |
| 112 | +```sh |
| 113 | +eval $(luarocks path --no-bin) |
| 114 | +``` |
0 commit comments