Skip to content

Instantly share code, notes, and snippets.

@askalee
Created October 23, 2017 06:54
Show Gist options
  • Save askalee/f2f489cff739fad341248864aafe0d4b to your computer and use it in GitHub Desktop.
Save askalee/f2f489cff739fad341248864aafe0d4b to your computer and use it in GitHub Desktop.
Run unit test each time before the main script runs
def RunUnitTests() {
println("INFO: Running Unit Tests")
def tests = [:]
// define unit tests here
tests["GetNodesByLabel"] = {
assert GetNodesByLabel().collect{it.name}.size() > 0
}
// end of define unit tests
tests.each {testName, testScript ->
println("UNITTEST [${testName}]: Run...")
testScript()
println("UNITTEST [${testName}]: Passed")
}
println("INFO: End of Unit Tests, all tests should have passed")
}
RunUnitTests()
if(build.buildVariableResolver.resolve("HandleUnitTests") == "TestOnly"){
println("WARNING: Run tests only, skip running main script")
return 0
}
// Put main script here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment