From e18794676d69daaaefbfe795df3a5f3ea1f523bc Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Wed, 2 May 2018 11:24:50 -0400 Subject: [PATCH] #339 Can now control whether teardown scripts run or not in mlUnitTest --- build.gradle | 2 +- examples/unit-test-project/build.gradle | 8 +++++--- examples/unit-test-project/gradle.properties | 3 ++- .../test/suites/My Tests/suite-teardown.xqy | 1 + .../root/test/suites/My Tests/teardown.xqy | 1 + gradle.properties | 6 ++++-- .../com/marklogic/gradle/MarkLogicPlugin.groovy | 3 ++- .../gradle/task/test/UnitTestTask.groovy | 17 ++++++++++++++++- 8 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/suite-teardown.xqy create mode 100644 examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/teardown.xqy diff --git a/build.gradle b/build.gradle index 88c7501a7..8f51ffadf 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ dependencies { compile mlDataMovementDependency compile group: 'commons-io', name: 'commons-io', version: '2.5' - compileOnly "com.marklogic:ml-unit-test-client:0.9.1" + compileOnly mlUnitTestDependency testCompile localGroovy() testCompile gradleTestKit() diff --git a/examples/unit-test-project/build.gradle b/examples/unit-test-project/build.gradle index d400aa69d..80a182b9b 100644 --- a/examples/unit-test-project/build.gradle +++ b/examples/unit-test-project/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + mavenLocal() // Needed for ml-unit-test-client dependency until it's available via jcenter() maven { @@ -8,7 +9,7 @@ buildscript { } } dependencies { - classpath "com.marklogic:ml-unit-test-client:0.9.1" + classpath "com.marklogic:ml-unit-test-client:${mlUnitTestVersion}" classpath "com.marklogic:ml-gradle:${mlGradleVersion}" } } @@ -18,6 +19,7 @@ apply plugin: "com.marklogic.ml-gradle" repositories { jcenter() + mavenLocal() // Needed for ml-unit-test and ml-unit-test-client dependencies until they're available via jcenter() maven { @@ -26,9 +28,9 @@ repositories { } dependencies { - mlRestApi "com.marklogic:ml-unit-test:0.9.1" + mlRestApi "com.marklogic:ml-unit-test:${mlUnitTestVersion}" // For running ml-unit-test tests via JUnit - testCompile "com.marklogic:ml-unit-test-client:0.9.1" + testCompile "com.marklogic:ml-unit-test-client:${mlUnitTestVersion}" testCompile "junit:junit:4+" } diff --git a/examples/unit-test-project/gradle.properties b/examples/unit-test-project/gradle.properties index 5bae3dd4b..85b95138c 100644 --- a/examples/unit-test-project/gradle.properties +++ b/examples/unit-test-project/gradle.properties @@ -1,4 +1,5 @@ -mlGradleVersion=3.6.0 +mlGradleVersion=3.6.3 +mlUnitTestVersion=0.10.0 mlHost=localhost mlAppName=unit-test-example diff --git a/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/suite-teardown.xqy b/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/suite-teardown.xqy new file mode 100644 index 000000000..238aa4178 --- /dev/null +++ b/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/suite-teardown.xqy @@ -0,0 +1 @@ +xdmp:log("Suite teardown") diff --git a/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/teardown.xqy b/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/teardown.xqy new file mode 100644 index 000000000..1ed5ade36 --- /dev/null +++ b/examples/unit-test-project/src/test/ml-modules/root/test/suites/My Tests/teardown.xqy @@ -0,0 +1 @@ +xdmp:log("Test teardown") diff --git a/gradle.properties b/gradle.properties index 06bf09fa0..313658562 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ group=com.marklogic -version=3.6.2 -mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.6.2 +version=3.6.3 + +mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.6.3 mlcpUtilDependency=com.marklogic:mlcp-util:0.9.0 mlDataMovementDependency=com.marklogic:marklogic-data-movement-components:1.0 +mlUnitTestDependency=com.marklogic:ml-unit-test-client:0.10.0 diff --git a/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy b/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy index f8811e285..3fcf83433 100644 --- a/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy +++ b/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy @@ -276,7 +276,8 @@ class MarkLogicPlugin implements Plugin { "Can use -PsuiteName to override the name of the test suite, and -PtestName to override the name of the test module.") project.task("mlUnitTest", type: UnitTestTask, group: unitTestGroup, description: "Run tests found under /test/suites in the modules database. " + "Connects to MarkLogic via the REST API server defined by mlTestRestPort (or by mlRestPort if mlTestRestPort is not set), and uses mlRest* properties for authentication. " + - "Use -PunitTestResultPath to override where test result files are written, which defaults to build/test-results/marklogic-unit-test.") + "Use -PunitTestResultPath to override where test result files are written, which defaults to build/test-results/marklogic-unit-test. " + + "Use -PrunTeardown and -PrunSuiteTeardown to control whether teardown and suite teardown scripts are run; these default to 'true' and can be set to 'false' instead. ") logger.info("Finished initializing ml-gradle\n") } diff --git a/src/main/groovy/com/marklogic/gradle/task/test/UnitTestTask.groovy b/src/main/groovy/com/marklogic/gradle/task/test/UnitTestTask.groovy index 34148d677..7d11bdb01 100644 --- a/src/main/groovy/com/marklogic/gradle/task/test/UnitTestTask.groovy +++ b/src/main/groovy/com/marklogic/gradle/task/test/UnitTestTask.groovy @@ -25,7 +25,22 @@ class UnitTestTask extends MarkLogicTask { def client = appConfig.getTestRestPort() != null ? appConfig.newTestDatabaseClient() : appConfig.newDatabaseClient() try { def testManager = new TestManager(client) - def suites = testManager.runAllSuites() + + boolean runTeardown = true + boolean runSuiteTeardown = true + if (project.hasProperty("runTeardown")) { + runTeardown = Boolean.parseBoolean(project.property("runTeardown")) + } + if (project.hasProperty("runSuiteTeardown")) { + runSuiteTeardown = Boolean.parseBoolean(project.property("runSuiteTeardown")) + } + + println "Run teardown scripts: " + runTeardown + println "Run suite teardown scripts: " + runSuiteTeardown + println "Running all suites..." + long start = System.currentTimeMillis() + def suites = testManager.runAllSuites(runTeardown, runSuiteTeardown) + println "Done running all suites; time: " + (System.currentTimeMillis() - start) + "ms" def report = new DefaultJUnitTestReporter().reportOnJUnitTestSuites(suites) println report