I'm looking forward to reuse code for bats unit tests on different environments. What I want to know if it's possible to have common @test code for both files in one place.
My first unit test file is to be run on my development environment:
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
setup() {
# Development environment
PROJECT_PATH="/d/develop/myproject"
}
@test 'check project path' {
cd $PROJECT_PATH
run git fetch origin
refute_output --partial 'fatal: not a git repository (or any of the parent directories): .git'
}
My second unit test file runs same test and is to be run on deployment or production environment:
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
setup() {
# Production environment
PROJECT_PATH="/var/myproject"
}
@test 'check project path' {
cd $PROJECT_PATH
run git fetch origin
refute_output --partial 'fatal: not a git repository (or any of the parent directories): .git'
}
As you see code for test is the same and only change $PROJECT_PATH value on the setup function.
Thanks for taking your time to read this question.