How To Edit bats-core Files

.bats files are edited as regular Bash files.

Live Templates

You can use the live templates feature to quickly create new test functions in a file. The following sections list the available live templates and explain how to use them.

@test
A line, which starts with @test, defines a new bats–core test.
  1. Enter @test
  2. Press the TAB key to insert a new test function into the file.
  3. The editor first asks for the description of the new test. Enter a value, e.g. my name, and press Enter .
  4. The caret now moves into the body of the function and now allows you to implement your new test.
1
2
3
@test "my name" {
    # ← caret is put here
}
setup
The function setup is executed before each test function, if it’s defined.
  1. Enter setup
  2. Press the TAB key to insert a new setup function into your file. Your new function now looks like this:
1
2
3
4
# executed before each test
setup() {
    # ← caret is put here
}
teardown
The function teardown is executed after each test function, if it’s defined.
  1. Enter teardown
  2. Press the TAB key to insert a new teardown function into your file. Your new function now looks like this:
1
2
3
4
# executed after each test
teardown() {
    # ← caret is put here        
}

Limitations