Functional Tests

Last Updated: Dec 9, 2022
documentation for the dotCMS Content Management System

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:

ParameterDescriptionDefault Value
classSpecifies which JUnit class to run.If this parameter is not supplied, all the tests are run.
methodSpecifies 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.
resultTypeValid values are:
  • file: Generates an XML report file in the folder /webapps/ROOT/dotsecure/logs/test/.
  • plain: Displays the results of the tests as plain/text in the browser and console, and also appends the result of the tests to the log file /webapps/ROOT/dotsecure/logs/dotcms-test.log.
    (This method is very useful when testing locally).
file

Examples

class

URLDescription
http://localhost:8082/dotTest?class=com.dotcms.rest.WebResourceTest
Only executes the WebResourceTest class
http://localhost:8082/dotTest
Executes all the tests

method

URLDescription
http://localhost:8082/dotTest?class=com.dotcms.rest.ContentResourceTest&method=categoryAndTagFields
Executes only the categoryAndTagFields method of the ContentResourceTest class.

resultType

URLDescription
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:

ResultCode
All tests passed200
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:

  1. Use ant tasks:
    • Execute the test-dotcms task of the build.xml.
  2. Make direct calls to the servlet:
    1. Execute the “deploy-tests” task of the build.xml
    2. Run the application
    3. 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 {

    }

On this page

×

We Dig Feedback

Selected excerpt:

×