Spring Boot Testing - Keep the App running for longer

thonnor :

I have a Spring Boot application that receives an API instruction and then begins streaming in a file, hash totaling the file and then streaming it out somewhere else. In the real world this could take one second or it could take hours.

I'd like to add that using POSTMAN and curl we have fully tested this app and it works as per its design.

We need to cover this with JUnit.

We are using JUnit 5 I am trying to run a test where the API is called on a very small file to process (probably a few seconds in total) However the Spring Boot Application shuts down too quickly meaning that the test never actually completes.

The Inbound/Outbound Streams are both performed using @Aysnc methods which I don't think helps as these dive into separate threads.

I also whole-heartedly believe that this kind of processing should not be tested with JUnit. But we have a coverage target to hit. This is IST testing.

My question is...

Does anyone know of a way to keep the Spring Boot Application running for a longer time, within the JUnit?

Just long enough to see the file come out the other side.

I've not used any Mock Frameworks at this point in time. I'm open to this idea but some direction would be appreciated if this is a viable option.

Sam Brannen :

You'll need to introduce some sort of blocking/polling to wait for the asynchronous task to complete before allowing the @Test method to complete.

Awaitility provides good support for testing scenarios like that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Pass command line args to Java app (Spring Boot) running in Docker

Spring boot web app not running on tomcat 9

Issues running example keycloak spring-boot app

Running a MVC app using Spring Boot + Hibernate + MySql

Exception when running Spring Boot app inside of Docker

Java app working when running spring boot but not with Apache

error while running spring boot app on localhost

Feign UnsatisfiedDependecyException when running my spring boot app

Spring Boot ApplicationListener not running at app startup

How to keep an Android App logged in indefinitely with Spring Boot Server?

Running a Spring Boot app behind nginx

Integration testing a Spring Boot web app with TestNG

Spring Boot - long running application for non-web app

Spring Boot Camel Testing

Keep the app running in foreground

Testing a spring boot service without running @SpringBootApplication

keep-alive configurations of spring-boot app (with embedded tomcat)

securing spring boot app with mTLS - running on Swisscom App Cloud

JVM crashes when running Spring Boot web app

Running a Spring Boot app using ./gradlew appRun

Connection refused by Spring boot app running in different docker container

Running Spring Boot 2 app on SAP Neo Cloud Tomcat

What's the way of running KSQL from spring boot app

Spring Boot APP - Unit Testing

Simple solution for testing spring boot and angular2 app?

JSF components are not rendered when running Spring Boot app on Eclipse Tomcat

Running a Spring Boot App on Azure WebJob with a Schedule

How to scale a Spring Boot app to keep the same performance?

Spring Boot + Postgresql not creating table when running app