You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Setup

This example shows how to setup an application for tests with cargo.

Executing Cargo Tests with Maven

The example above has no maven profiles - that means the cargo tests are executed automatically during a maven build like:

mvn clean install

Writing Cargo Tests

The Cargo base test infrastructure module provided by CODI offers some helpers for easier testing.

Simple Cargo Test with the base infrastructure module of CODI

@RunWith(JUnit4WithCargo.class)
public class DemoTestCase extends AbstractCargoTest
{

    // NOTE that new @Test means new WebClient means new WindowContext

    @Test
    public void checkSubmittedValueAfterNavigation() throws Exception
    {
        SimplePageInteraction pageInteraction = new SimplePageInteraction(getTestConfiguration()) //the default config
                .with(Pages.Page1.class)   //adds view-config for /pages/page1.xhtml to the current context
                .with(Pages.Page2.class)   //adds view-config for /pages/page2.xhtml to the current context
                .start(Pages.Page1.class); //start the test with /pages/page2.xhtml

        pageInteraction
                .useForm("form1") //activate form1
                .setValue("form1:input1", "1") //set a value
                .click("form1:button1"); //click on a button

        pageInteraction
                .checkState(Pages.Page2.class); //check the result - due to a redirect we have a new url - also the window-id is checked
                .checkTextValue("output1", "1"); //check the value of a text output
    }
}

Debugging Cargo Tests

Start Jetty

mvn jetty:run-exploded -Dmaven.skip.test=true -PjettyConfig

and afterwards it's possible to run the JUnit test in your IDE (in the debug-mode).

  • No labels