I’m not sure if there’s a proper word for this. I want to be able to write a list of tests in plain text, then convert them into a list of empty test functions.
For example, if I write
a user can view all documents
documents can be created
documents can edited
I would like to then be able to do something, like highlight the lines and run an extension, which would transform those lines into
/** @test */
public function a_user_can_view_all_documents()
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
/** @test */
public function documents_can_be_created()
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
/** @test */
public function documents_can_edited()
{
$this->markTestIncomplete('This test has not been implemented yet.');
}
I currently use snippets to generate the test code without a function name. But I still have to do this for each test, AND type out the test names, which is a bit annoying since they’re in snake_case.
Is there a built-in feature of VS Code that can do this?
2
Answers
It's not as straight forward as I would like, but what I'm going with for now is:
You can create a snippet like this:
and then either trigger it from that prefix – after selecting each line – or to simplify create a keybinding which will select the line for you and also insert the snippet. Use this keybinding (in your
keybindings.json
file):Now if you really want to make one big selection of all the lines and trigger it just once that is going to be harder. Might be possible with an extension that examines the selection and ignores the empty lines.