Unit testing a Spring MVC controller that returns DeferredResult - spring-test

I am trying to test a Spring 3.2.1 controller that returns a list of DeferredResult objects. I was using the following test as a guide, but I am wondering if this test is an integration test and not a unit test?
https://github.com/SpringSource/spring-mvc-showcase/blob/master/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java
When I run my unit test, I get:
Caused by: java.lang.UnsupportedOperationException: No async support in a pre-Servlet 3.0 runtime
In researching this error, I believe it has to do with the async support included in the servlet 3.0 api being needed, which makes sense, but what Maven dependencies do I need to include to make the test pass? Has anybody written a successful spring mvc controller unit test for DeferredResults like the one in the link? (Again, I am assuming that the link above is a unit test and not an integration test).
Thanks

Related

Cucumber Framework Migration - Existing Rest Assured to Karate Framework

I am working as automation tester for banking domain account. I have a query and need your help.
Current Approach :
1.The framework which we are using for API-Services testing is Java based - Serenity -Cucumber framework using Rest Assured.
2.All the script development/script maintenance activities related to this framework is taken care by the automation testers in our team.
3.Few weeks before , we got to know about Karate framework and completed the PoC( Proof of concept).
4.All went well and we are in the plan to migrate our existing Rest assured java code Karate framework.
The reason for migration - Karate framework Api services testing can be able to do by Manual testers as well.So we are in the plan for migration.
Query
We have almost 80 web services already developed in Rest assured and running successfully.
Also for migration, all the services are inter-dependent. So we have to use both Res-assured and Karate framework code together ,unless it's fully migrated.
Can't able to migrate all the services immediately ,it's a time taken effort.
Is it possible to run karate framework and Rest Assured Java code in the same scenario.
Scnario given in Karate Feature file:
Given urlCustomerservices
When method get
Then status 200
def getCustIDfromUserservices=newcallJavaFunction().getcustid("user","password")
print getCustIDfromUserservices
This "getcustid" have the Rest assured java code for "Post" call service to get the customer number.
When I am running this in code karate framework , getting this error -
"io.restassured.internal.RequestSpecificationIMpl.invokeMethod(java/lang/String;Ljava/lang/object;)Ljava/lang/object;
Could any help in this. Whether can we run both karate and Rest assured code together in same scenario in karate framework . If yes, why am getting this error, when am trying to get the response in Rest assured.
First I'll say that this is not something we claim to support :) So you are on your own.
That said, it sounds like a simple library conflict. My guess is your existing Maven pom.xml has a lot of libraries floating around. You will need to do some investigation and find out what maven exclusions you need to do or which libraries need explicit versions specified. If you are lucky, switching from karate-apache to karate-jersey may do the trick.
Also I strongly recommend creating a Karate quickstart, then adding the extra stuff one by one in "hello world" mode and see what causes the problem. Use the mvn dependency:tree command and see the differences between a Karate project and yours. If you know how to use Maven profiles, that may be one way to go. All the best !
Worst case, fall back to 2 maven modules and run 2 test-suites, it is fine and not the end of the world. You can gradually migrate.
EDIT - also see https://stackoverflow.com/a/65628686/143475

Generate code coverage for integration tests

In the ML model which uses python3.6, flask restful, gunicorn (wsgi), nginx and docker, I do not have good unit test coverage but cover almost all scenarios in my integration and regression tests by invoking REST Api developed using flask restful. REST API is deployed into container.
I generated code coverage report using coverage i.e. https://pypi.org/project/coverage/ and the report is generated based on my unit tests. But, I also need to see if there is a way to get code coverage using integration and regression tests as well. Since API is deployed into a container, I am not sure how I can get code coverage using integration and regression tests because I invoke REST APIs for the same.
Please let me know if someone has solved this problem already ?

Integration Testing and Load Testing : using the same scenarii (JVM)

At the moment, I'm using two different frameworks for REST APIs integration testing, and load/stress testing. Respectively : geb (or cucumber) and gatling. But most of the time, I'm re-writing some pieces of code in load / performance scenarii that I've been writing for integration testing.
So the question is : is there a framework (running on the JVM) or simply a way, to write integration tests (for a strict REST API use case), preferably programmatically, then assemble load testing scenarios using these integration tests.
I've read cucumber maybe could do that, but I'm lacking a proper example.
The requirements :
write integration tests programmatically
for any integration test, have the ability to "extract" values (the same way gatling can extract json paths for instance)
assemble the integration tests in a load test scenario
If anyone has some experience to share, I'd be happy to read any blog article, GitHub repository, or whatever source dealing with such an approach.
Thanks in advance for your help.
It sounds like you want to extract a library that you use both for your integration tests as well as your load test.
Both tools you are referring to are able to use external jar.
Suppose that you use Maven or Gradle as build tool, create a new module that you refer to from both your integration tests and your load tests. Place all interaction logic in this new module. This should allow you to reuse the code you need.

Executing cucumber (gherkin scripts) with SOAP UI ?

I'm trying to find possibilities for the BDD approach of testing my web services with SOAP UI & Cucumber. Is there any way to achieve this ? Please advise
Thanks
Exactly, both SOAPUI and Cucumber are different test runners. You have to choose between both. Except that SOAPUI provides you http-clients for calling services and Cucumber can contain any tests that use different libraries/clients to do different type of testing.
Presuming that you are thinking to use SoapUI just as http-client for services testing, its better to use Jersey client and use Cucumber/JBehave as BDD runner.
I Do Agree with #I Am's answer. Using Jersey or other httpclient do the needful. In case of jersy with BDD you can use QAF with Web service plugin. You can use cucumber gherkin or QAF BDD or pure java for test authoring. QAF bdd for web-service may look like below:
SCENARIO: My Fist webservice call
META-DATA: {"description":"Just for learning purpose"}
When user requests '${get.sample.call}'
Then response should have status 'OK'
END
Where, get.sample.call will be in properties file holding request details.

Spring Integration with Cobertura

I am using spring integration in my application. I have written Junit test cases and initializing spring xml file using spring test framework. I am trying to setup Cobertura but it is not working properly. I am generating report via maven plugin. Just wanted to check if I am using the right tool for code coverage. If not, what else is the good option with spring integration. Thanks.
"Not working properly" will not help anyone understand your problem.
I can't speak to cobertura, but for Spring Integration itself, we use JaCoCo for code coverage from the gradle build. It produces html reports in the build directory and the output file is used by Sonar too.
I use eclemma in eclipse.

Resources