Reputation: 1246
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.
Upvotes: 0
Views: 1484
Reputation: 31257
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.
Upvotes: 1