Document About Testing

Our team wants to write ui tests(jmix screen) and unit tests.

Will the jmix document be added in the future about Unit Test and Web Integration Tests


By the way, Is there any estimate when a more complete document will be released?


We are constantly working on the documentation and updating it as soon as new sections are ready, usually each week.

Until there is something about testing in the docs, I will explain how to write integration tests for business logic and UI with examples.

Firstly, a Jmix application is quite a standard Spring Boot app, so you can write tests running in the Spring container using @SpringBootTest. Such a test is generated in any new project. Below is an example demonstrating how to write tests working with your entities or services:

class UiTestDemoApplicationTests {

	SystemAuthenticator authenticator;

	DataManager dataManager;

	void setUp() {

	void tearDown() {

	void adminUserExists() {
		Optional<User> adminOpt = dataManager.load(User.class)
				.query("e.username = ?1", "admin")

The only specific to Jmix here is SystemAuthenticator - it provides a current authentication to your code, otherwise the framework access control won’t allow you to work with data.

To see more helpful output in the log, you can add the following application properties: = debug
logging.level.eclipselink.logging.sql = debug

Testing UI screens is more complicated, as it requires the setup of the presentation layer. The jmix-ui-test-assist module simplifies the task and provides the infrastructure for writing UI tests with the Spock framework. Below is an example of using it for testing the UserBrowse screen of a new project.

In build.gradle, add groovy plugin and test dependency to jmix-ui-test-assist:

plugins {
    id 'io.jmix' version '1.0.2'
    id 'java'
    id 'groovy'

apply plugin: 'org.springframework.boot'

jmix {
    bomVersion = '1.0.1'

// ...
dependencies {
    // ...
    testImplementation 'io.jmix.ui:jmix-ui-test-assist'

Add the src/test/groovy source root and the test class inside:

@ContextConfiguration(classes = UiTestDemoApplication)
class UserBrowseTest extends UiTestAssistSpecification {

    SystemAuthenticator authenticator

    protected void setupAuthentication() {

    protected void cleanupAuthentication() {

    def "admin user is shown"() {
        def mainScreen = screens.create(MainScreen, OpenMode.ROOT)

        def userBrowseScreen = screens.create(UserBrowse)

        CollectionContainer<User> usersDc = userBrowseScreen.screenData.getContainer('usersDc')
        Table<User> usersTable = userBrowseScreen.window.getComponent('usersTable')

        usersDc.items.find(user -> user.username == 'admin') != null
        usersTable.getItems().items.find(user -> user.username == 'admin') != null

UiTestAssistSpecification base class is provided by the jmix-ui-test-assist module, it’s a subclass of Spock’s Specification. The @ContextConfiguration annotation specifies the main application class.

In your test class, you should implement the setupAuthentication() and cleanupAuthentication() methods similarly to how you do it in the first example of testing business logic.

See the entire example project attached: (82.6 KB)


UPDATED 2021-08-06 to conform changes in Jmix 1.0.1, particularly changed the base class for UI test, added setupAuthentication() and cleanupAuthentication() methods.


Please notice that I updated my answer above to conform changes in Jmix 1.0.1.
Changed the base class, added setupAuthentication() and cleanupAuthentication() methods in UI test.

Given the importante of Testing, maybe this thread can be pinned until the documentation includes this?

Thx @krivopustov for the examples, they’ll come in handy! It also looks like we won’t need addons for UI testing like in CUBA!

@marc & @a616101 You probably saw is now available
Thanks JMIX team!