As more organizations and teams embrace Continuous Testing, Developers are expected to do reliable, repeatable testing of code along with development. This ensures that they identify issues early and fix them to avoid delays later on in the cycles.
Using CA Service virtualization enables developers to have a predictable environment / services for them to run their unit tests without having to hard-code responses. However, developers may prefer to use their IDE than to use a separate interface for these activities.
With Service virtualization 10.5 release, we are providing a new solution called 'Service Virtualization as Code' or SV as Code. This solution provides Java annotations that can be used in Junit tests to deploy virtual services before starting the tests. These Java annotations help embed virtual services in the code. This enables developers to write code to deploy virtual services to VSE directly from code and use it in the Junit Tests.
Below are some of the features of the solution.
- Create and Deploy a Virtual Service before a test
- Create and Deploy a Virtual Service before any test from the class
- Create and Deploy multiple Virtual Services before a test
- Create and Deploy with vrs
- Create and Deploy with rr-pair
- Create and Deploy with vsm
- Parameterized DevTest Virtual Service Annotation
- Generate RR Pairs Utility
This solution can be downloaded from - https://github.com/CA-DevTest/SV-as-Code-UnitTest
Pre-requisites for the solution
- DevTest server should be up and running and can be installed locally or on remote server.
- Need to setup registry url and VSE name through Java annotation @DevTestVirtualServer. These parameters will be used to build and deploy virtual services.
The annotations use DevTest REST API (DevTest Invoke 2) and is compatible with DevTest versions 8.0 to 10.5.
How do we get started?
Getting started is pretty easy. Just add the below repository and dependency to the pom file of your maven project.
Repository to be added
<repositories>
<repository>
<id>bintray-ca-sv</id>
<name>bintray-ca</name>
<url>http://ca.bintray.com/sv</url>
</repository>
</repositories>
Dependency to be added
<dependency>
<groupId>com.ca.devtest.sv.devtools</groupId>
<artifactId>devtest-unit-test-java</artifactId>
<version>1.3.2</version>
</dependency>
We have also provided a sample project 'lisabank-demo' in the url (download sourcecode.zip) that you can look at to understand the configuration.
An example of how to use the annotations is as as given below.
DevTestVirtualServer annotation lets you define the registryHost (local by default), VSE name (VSE by default), username (svpower by default) and password (svpower by default).
The VirtualServices rule defined will handle the SV-as-Code annotations during the Junit lifecycle.
The next annotation DevTestVirtualService which needs to be added above each test definition, lets you define the virtual service by providing the serviceName, basePath for the service, port for the service, working folder (which is the folder where rr pairs, vrs file, vsm file etc. are present), requestDataProtocol (defines the data protocol to be used to process transactions).
In addition to defining virtual services at test level, they can be defined at a class level, which will be deployed once at class level. That will use a ClassRule named VirtualServiceClassScopeRule as shown below. This will let us defined DevTestVirtualService annotation outside the class as shown below.
Learn more about the solution and download the same here - https://github.com/CA-DevTest/SV-as-Code-UnitTest
Look forward for more blogs and videos on the solution.