marklogic-unit-test is a testing framework that allows a project to test MarkLogic code. With one import a project immediately has access to:
- A framework for writing and running MarkLogic unit tests, including several built in assertion functions
- A UI for viewing and running unit tests entirely within MarkLogic
- A REST endpoint to run and report unit tests with other tools
Testing MarkLogic from a Java project is made easy with marklogic-junit5:
- Write MarkLogic tests entirely from Java
- Easily integrate MarkLogic unit tests into your JUnit 5 project
MarkLogic unit test can easily be integrated into your project as an ml-bundle. The following steps will configure a project to import and use marklogic-unit-tests.
If you'd like to skip straight to the end, you can check out a working example project.
You can use that project's build.gradle
file as an example of how to use marklogic-unit-test in your own project.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath "com.marklogic:marklogic-unit-test-client:1.0.beta"
classpath "com.marklogic:ml-gradle:3.14.0"
}
}
apply plugin: "com.marklogic.ml-gradle"
repositories {
jcenter()
}
dependencies {
mlBundle "com.marklogic:marklogic-unit-test-modules:1.0.beta"
}
// Settings for any ml-gradle project
mlHost=localhost // Assuming local development
mlAppName=my-app // Application name, defaults to my-app
mlRestPort=8003 // Application Port, defaults to 8003
mlUsername= // Username used to manage MarkLogic
mlPassword= // Password used to manage MarkLogic
// Settings specific to marklogic-unit-test
mlTestRestPort=8004 // Testing port, view and run tests from this port
// ml-gradle supports deploying to multiple environments (https://github.com/marklogic-community/ml-gradle/wiki/Configuring-ml-gradle#environment-based-properties).\
// Add the following line to gradle-{env}.properties files for which you would like to deploy the tests. Typically
// tests are only deployed to environments that execute automated tests, like local development and CI environments.
mlModulePaths=src/main/ml-modules,src/test/ml-modules
Now that the environment is configured to load tests and setup a test application servier its time to deploy everything.
./gradlew mlDeploy
To enable quicker feedback between code updates and automated test runs, use the mlWatch task to automatically deploy changes to MarkLogic
./gradlew mlWatch
Open a web browser to http://localhost:8004/test/. This is where tests are selected, run, and results are displayed.
If this is a project that's new to marklogic-unit-tests no test suites are displayed because there are no tests.
Creating test suites is easy using the mlGenerateUnitTestSuite gradle task. Run the following to setup a sample test suite:
./gradlew mlGenerateUnitTestSuite
Now a new test suite has been generated in src/test/ml-modules/root/test/suites
called SampleTestSuite
.
If mlWatch
is being used, refreshing the web browser at http://localhost:8004/test/ will now show the newly created
SampleTestSuite
. The suite can be run using the Run Tests button at the top or bottom of the page.
Check out the marklogic-junit5 sub-project to get started using marklogic-junit5.