vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Add support for generating tests by comment

Open Rednas83 opened this issue 2 years ago • 2 comments

Writing tests can be time consuming and may also not be very accessible or very easy to understand for everyone.

Something like image Advantages

  • Everything in 1 file (code, unit test & documentation)
  • Structured way of commenting
  • Potentially it could even generate an interactive playground for documentation/manual testing

Disadvantages

  • Perhaps not suitable for more complex unit tests

Inspired by https://github.com/aaron-bond/better-comments image

Rednas83 avatar Aug 03 '23 14:08 Rednas83

Please upvote if you like this idea. I think it should be very do-able.

Rednas83 avatar Jan 12 '24 08:01 Rednas83

It would also be nice to have a test-generator utility, eg. something similar to what Jest or Playwright have: create scaffolding for the current function, class, module so I don't have to write everything from scratch. It should be easily template-able. In Visual Studio (not Code) you can right click when in the method and just say "Create Unit Test" which will create the test file for you and do a basic template. Saves a lot of time and helps code/test maintenance as everything is done in a consistent way.

molt2020 avatar May 21 '24 08:05 molt2020

I know the status is discussion but it already received 6 upvotes so it would at least make 6 people happy😉

Are there plans for supporting this? Any thoughts about the matter?

Rednas83 avatar Jul 05 '24 10:07 Rednas83

Good thing that you mentioned that. No, we are not planning to introduce any comment parsing feature in core: https://github.com/vitest-dev/vitest/issues/3035#issuecomment-2051246359

sheremet-va avatar Jul 05 '24 13:07 sheremet-va