feat:🎁 Run tests from buffer
Closed this issue · 13 comments
Add the ability to run tests from a file or individual test methods.
This will be useful in large solutions where the solution has more than 100 projects.
It would also help if test discovery fails (I found this bug in a large solution with 25k+ tests, but haven't had time to tackle it yet) - so that I could run tests in a file or just the method I need.
There is a WIP implementation of this in #140
@molostovvs I think I might have something usable now. Would you want to test it?
- Update options; add
enable_buffer_test_execution = true
as property under the test_runner section - Open the testrunner window
- Close the testrunner window
- Open a file containing a test
- Navigate to the line which has the gutter sign
- Press
<leader>r
- profit??
I'm with my family this weekend. will test this on Monday, thanks for your work!
Awesome, no rush :D
Just checked it out, works great!
Is there a plan to synchronize the test status from the status column in the buffer and in the Dotnet testrunner
window?
Yeah a couple things on my roadmap, either in this PR or future ones
-
Improve buffer indicators for runnable tests
The current icons kinda suck so i need better nerdfont icons, or use something like line highlights, virtual text etc.. Open to suggestions on this one -
Sync testresults between buffer and testrunner
-
Add debugging so you can run
<leader>d
to launch debugger and start debugging the test -
Add some sort of lua function that you can call to run the test discovery in the background without opening and closing the testrunner
Update:
- Added new gutter sign for test
- Added F# support
- Added bidirectional sync of status between testrunner and buffer
@molostovvs Do you mind retesting?
I've got character synchronization working like this:
if I run the test from the buffer, the characters in the Dotnet testrunner
window are updated, but if I run the test in Dotnet testrunner
, the character in the buffer is not updated until I do :e
.
It seems to me that the symbol to indicate a test in the buffer should be “wide”, like flask symbol from Dotnet testrunner
, because now if a test is successful, then on the line above appears the symbol “checkmark”, which is 2 times wider, which, as it seems to me, is not very aesthetic. Why not use the symbol from Dotnet testrunner?
And what about having a success/fail symbol replace the symbol for the test itself? I.e. replace the flask symbol with a “checkmark”
Oh, and it's also not very convenient that you can't override mappings to call a test from the buffer, which makes me change it in the source code every time
Fixed the following
- Customizable keymappings
- Gutter icon is same as test icon from testrunner
- Status sign overwrites the gutter icon instead of being placed on the line above
if I run the test from the buffer, the characters in the Dotnet testrunner window are updated, but if I run the test in Dotnet testrunner, the character in the buffer is not updated until I do :e.
The sign placement is using BufReadPost
to trigger. I changed this to BufEnter
which might solve your problem. I didnt notice this because I have a check to ensure the buffer doesnt become stale when updated from other sources
-- auto reload file when contents are written from an external source. e.g github reset --hard
vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
pattern = "*",
command = "if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif",
})
I made all keybindings for testrunner and buffer running customizable now in options
I merged the pr now because I didnt want the branch to live for too long and the core features should be present and working. If you notice any bugs, improvements etc just open a new issue please
And thanks for all the feedback and testing! It helps a lot