If you build dotCMS from source code, dotCMS provides Functional tests with the source code which allow you to test the system against functional requirements. Functional tests are developed using user stories to ensure the end result of dotCMS processes (data, return values, outputs, etc.) match the expected user requirements and expectations.
Requirements
To enable running functional tests from the command line, the following gradle command must be run before deploying dotCMS and building your Tomcat directory (using the ./gradlew deployWarTomcat
command mentioned in the developing from source documentation):
./gradlew deployWarTomcatTests
Functional Test URLs
There are diferent ways to call the tests and, depending on the way they are called, the result will change as well. There are three parameters that can be passed to the test server:
Parameter | Description | Default Value |
---|---|---|
class | Specifies which JUnit class to run. | If this parameter is not supplied, all the tests are run. |
method | Specifies which test method of a test class you want to run. (This must be combined with the “class” parameter). | If this parameter is not supplied, all methods are run. |
resultType | Valid values are:
| file |
Examples
class
URL | Description |
---|---|
http://localhost:8082/dotTest?class=com.dotcms.rest.WebResourceTest | Only executes the WebResourceTest class |
http://localhost:8082/dotTest | Executes all the tests |
method
URL | Description |
---|---|
http://localhost:8082/dotTest?class=com.dotcms.rest.ContentResourceTest&method=categoryAndTagFields | Executes only the categoryAndTagFields method of the ContentResourceTest class. |
resultType
URL | Description |
---|---|
http://localhost:8082/dotTest?resultType=file | XML file |
http://localhost:8082/dotTest?resultType=plain | Plain/text result |
http://localhost:8082/dotTest | XML File (the default) |
http://localhost:8082/dotTest?class=com.dotcms.rest.WebResourceTest&resultType=plain | Plain/text result |
http://localhost:8082/dotTest?class=com.dotcms.rest.WebResourceTest | XML File (the default) |
Return Code
The test servlet will return one of two codes to indicate the status of the tests:
Result | Code |
---|---|
All tests passed | 200 |
Any test failed (even a single test) | 500 |
Sample Results
Plain Text
XML File
All Functional Tests Suite
The AllTestsSuite.java file contains the names of all the functional test Java classes. This file can be found in the /src/functional-test/java/com/ testing package.
Running the Suite
You may run the test suite in two ways:
- Use ant tasks:
- Execute the test-dotcms task of the build.xml.
- Make direct calls to the servlet:
- Execute the “deploy-tests” task of the build.xml
- Run the application
- Make the calls directly to the test servlet.
Adding Tests
You can add unit tests for your classes by adding entries for each class to the test module in the /test/ folder in your dotCMS build folder. This allow you to call your tests directly (specifying the class and/or test method).
If you wish for your tests to be run when the ALLTestsSuite is run, you must also add your tests to the main test suite.
The following shows the format of an entry for a test in the test module:
@RunWith ( Suite.class )
@Suite.SuiteClasses ( {
FieldFactoryTest.class,
StructureFactoryTest.class,
ContentletFactoryTest.class,
ContentletAPITest.class
} )
public class AllTestsSuite {
}