Unit testing with springboot

Hello,

I am having trouble testing my application using the spring-boot-starter. I would like to have a new deployment for every test method. Therefore I am using the @Deployment annotation. But this does not work for me.
A test class looks like this:

@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class DecisionComponentTest {
    @Autowired
    @Rule
    public ProcessEngineRule processEngineRule;

    @Autowired
    private IDecisionComponent decisionComponent;

    @Autowired
    private IApplicationComponent applicationComponent;

    @Autowired
    private RuntimeService runtimeService;


    @Test
    @Deployment(resources = {"application_check.cmmn","document_request_en.bpmn","insurance_application_en.bpmn","risk_check_en.dmn"})
    public void testDecideOnApplication() throws ApplicationNotFoundException {
        Assert.assertEquals(0,runtimeService.createProcessInstanceQuery().count());
        NewApplication newApplication = applicationComponent.createApplication(ExampleApplication.createRiskyApplication());

        Assert.assertEquals(1,runtimeService.createProcessInstanceQuery().count());
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();

    }
}

The first assertion fails because of the previous tests.
Is there a good example for tests with springboot? Thanks!

I suppose your SpringBootApplication does an auto deployment of all processes/tables/… found in src/main/resources (either via spring detection or processes.xml).
This does not work well with using the ProcessEngineRule, because in addition to the rule @Deployments, you get the full auto deployment by spring.
For Spring integration tests, I would suggest not to use the rule, but instead manually clean up running instances in a junit @After method.

1 Like

Good idea. Thank you!

1 Like