I wish to offer any new java based project to have basic/generic smoke testing as part of the CICD pipeline on github-actions or ansible.
Rather than having the developers write smoke test cases for their applications I wish to serve them with default test cases that are auto-generated by a tool or plugin.
One such plugin that I remember is diffblue
It has github CICD integration example step as well.
I have a few challenges using its CLI (free license) and what it offers is why I wish to explore other options.
My repo structure is :
myrepo
|--src
|--classes
|--common
|--com
|--mybank
|--common
|--hello1.class
|--hello2.class
|--util
|--hello3.class
I tried to generate testcase java files which should as per documentation be generated at
myrepo
|--src
|--test
|--java
dcover -classpath "D:\maven\bin\mvn.bat" com.mybank.common.hello1does not generate any test cases java file, does not throw any error as per logs either incom.mybank.commonor insrc.test.javafolders.
Not sure what is wrong in my attempt to use the cli for a single java file or entire java repo project.
- I wish to explore alternate tools that may offer more services or are more popular.
Note: this project was build using ant build.xml
Kindly suggest.
First of all, your repo code is not a Maven project. For the standalone maven batch file to work, your project needs to be completely maven project containing pom.xml.
Note: DiffBlue won't work with Ant based projects.
So, consider migrating your Ant based codebase to Maven based codebase to use DiffBlue tool.
From Official DiffBlue Documentation:
Prerequisites:
Java 8 Update 351+, Java 11.0.17+ or Java 17.0.5+ are supported at this moment.
Only Maven 3.2.5+ or Gradle 4.9+ build tools are supported.
Any project (for use with Diffblue Cover) must compile and run with no failing unit tests. JUnit and TestNG testing frameworks are supported.
Example on how DiffBlue works with Maven:
Note: I'm using Mac to show how it works. The process is similar for Windows as well.
Read the documentation from here to setup DiffBlue CLI.
Execute
dcover versionto verify the DiffBlue installed or not.I have a spring-boot based maven project with this structure below.
I have a SampleController class with an endpoint
dividewhich throws ArithmeticException:Enter root project directory with
cdcommand.Note: Execute the command from root directory itself as DiffBlue is smart enough to read all the classes and packages.
The command to generate the test is as follow :
Example:
dcover create com.example.demo.SampleControllerCurrent project structure contains the test class after dcover got executed:
The test class generated from the above code is given below:
Console Logs:
Also, You can try for other tools like Cucumber Framework which is an excellent framework for writing test classes via .feature file in human understand syntax and capable of generating test classes based on the .feature files (it uses Gherkin language).
Update: I found one tool called TackleTest-Unit which is capable of generating Java based Unit test cases. The main thing of this tool is that it supports Ant.
Github Repo: https://github.com/konveyor/tackle-test-generator-cli
From README.md :
Read the docs for more. I feel that the tool looks promising. So, you can try it.