arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Commands Tests

You can test your custom commands running in console with craft test helper.

This will programmatically run the command if it has been registered in your project and assert that no errors has been reported.

hashtag
Available Assertions

The following assertions are available when testing command with craft.

hashtag
assertSuccess

Assert that command exited with code 0 meaning that it ran successfully.

hashtag
assertHasErrors

Assert command output has errors.

hashtag
assertOutputContains

Assert command output contains the given string.

hashtag
assertExactOutput

Assert command output to be exactly the same as the given reference output. Be careful to add eventual line endings characters when using this assertion method.

hashtag
assertOutputMissing

Assert command output does not contain the given reference output.

hashtag
assertExactErrors

Assert command output has exactly the given errors.

def test_my_command(self):
    self.craft("my_command", "arg1 arg2").assertSuccess()
  • assertSuccess
    assertHasErrors
    assertOutputContains
    self.craft("my_command").assertSuccess()
    self.craft("my_command").assertHasErrors()
    self.craft("my_command").assertOutputContains(output)
    self.craft("my_command").assertExactOutput(output)
    self.craft("my_command").assertOutputMissing(output)
    self.craft("my_command").assertExactErrors(errors)
    assertExactOutput
    assertOutputMissing
    assertExactErrors