Automated generation of java unit tests
Systems and techniques for automated generation of Java unit tests, in the context of testing a code base for a financial transaction software application, are described. An example method for automated generation of Java unit tests includes: identifying default values used in Java source code of a financial transaction software application that is programmed and capable to perform batch processing of a plurality of financial transactions; identifying classes in the Java source code that are invoked by the financial transaction software application, as invoked during the batch processing; generating mock classes for the identified classes that are invoked; creating unit tests to perform unit testing of the identified classes that are invoked, the unit tests configured to invoke the mock classes and use the default values for unit testing of the identified classes; and outputting the unit tests (and optionally, executing the unit tests).
1 . A method for automated generation of Java unit tests, performed with automated operations executed by at least one processor of a computer system, the method comprising:
identifying default values used in a code base of Java source code of a financial transaction software application by analyzing usage of primitives and Java Development Kit (JDK) classes in the Java source code, the financial transaction software application programmed to perform batch processing of a plurality of financial transactions;
identifying classes in the Java source code that are invoked by the financial transaction software application, the identified classes invoked during the batch processing of the plurality of financial transactions,
wherein the default values provide (i) respective values for using the primitives and (ii) respective values for using the JDK classes, and wherein the default values initialize the primitives and the JDK classes defined in the Java source code across multiple methods of the identified classes, when the identified classes are invoked during the batch processing of the plurality of financial transactions;
generating mock classes for the identified classes that are invoked during the batch processing of the plurality of financial transactions;
creating unit tests to perform unit testing of the identified classes that are invoked during the batch processing of the plurality of financial transactions, the unit tests configured to invoke the mock classes and use the default values for unit testing of the identified classes; and
outputting the unit tests in the computer system.
2 . The method of claim 1 , wherein the identified classes invoked in the Java source code include Java framework classes, and wherein generating the mock classes includes generating mock classes for the Java framework classes with use of one or more mocking framework classes.
3 . The method of claim 1 , wherein the identified classes invoked in the Java source code include respective methods and constructors, and wherein the unit tests are configured to invoke the respective methods and constructors.
4 . The method of claim 1 , further comprising:
causing the at least one processor to execute the unit tests and invoke one or more unit testing framework classes; and
providing results in the computer system based on execution of the unit tests.
5 . The method of claim 4 , wherein the identified classes that are invoked are identified based on respective classes included in a Java Archive (JAR) package file;
wherein creating the unit tests includes replicating contents of the package file for the respective classes; and
wherein the execution of the unit tests includes use of the replicated contents of the package file for the respective classes.
6 . The method of claim 5 , wherein providing the results based on the execution of the unit tests includes providing information relating to a usage of the generated mock classes by the execution of the unit tests.
7 . A non-transitory machine-readable storage medium comprising instructions for automated generation of Java unit tests that, when executed by a processor of a computing system, cause the processor to perform operations to:
identify default values used in a code base of Java source code of a financial transaction software application by analyzing usage of primitives and Java Development Kit (JDK) classes in the Java source code, the financial transaction software application programmed to perform batch processing of a plurality of financial transactions;
identify classes in the Java source code that are invoked by the financial transaction software application, the identified classes invoked during the batch processing of the plurality of financial transactions,
wherein the default values provide (i) respective values for using the primitives and (ii) respective values for using the JDK classes, and wherein the default values initialize the primitives and the JDK classes defined in the Java source code across multiple methods of the identified classes when the identified classes are invoked during the batch processing of the plurality of financial transactions;
generate mock classes for the identified classes that are invoked during the batch processing of the plurality of financial transactions;
create unit tests to perform unit testing of the identified classes that are invoked during the batch processing of the plurality of financial transactions, the unit tests configured to invoke the mock classes and use the default values for unit testing of the identified classes; and
output the unit tests.
8 . The non-transitory machine-readable storage medium of claim 7 , wherein the identified classes invoked in the Java source code include Java framework classes, and wherein generating the mock classes includes generating mock classes for the Java framework classes with use of one or more mocking framework classes.
9 . The non-transitory machine-readable storage medium of claim 7 , wherein the identified classes invoked in the Java source code include respective methods and constructors, and wherein the unit tests are configured to invoke the respective methods and constructors.
10 . The non-transitory machine-readable storage medium of claim 7 , wherein the instructions further cause the processor to perform operations that:
cause the processor to execute the unit tests and invoke one or more unit testing framework classes; and
provide results from execution of the unit tests.
11 . The non-transitory machine-readable storage medium of claim 10 , wherein the identified classes that are invoked are identified based on respective classes included in a Java Archive (JAR) package file;
wherein to create the unit tests includes replicating contents of the package file for the respective classes; and
wherein the execution of the unit tests includes use of the replicated contents of the package file for the respective classes.
12 . The non-transitory machine-readable storage medium of claim 11 , wherein to provide the results from the execution of the unit tests includes to provide information relating to a usage of the generated mock classes by the execution of the unit tests.
13 . A computer system configured for automated generation of Java unit tests, the computer system comprising:
at least one processor; and
memory comprising instructions that, when executed by the at least one processor, cause the at least one processor to perform operations to:
identify default values used in a code base of Java source code of a financial transaction software application by analyzing usage of primitives and Java Development Kit (JDK) classes in the Java source code, the financial transaction software application programmed to perform batch processing of a plurality of financial transactions;
identify classes in the Java source code that are invoked by the financial transaction software application, the identified classes invoked during the batch processing of the plurality of financial transactions,
wherein the default values provide (i) respective values for using the primitives and (ii) respective values for using the JDK classes, and wherein the default values initialize the primitives and the JDK classes defined in the Java source code across multiple methods of the identified classes when the identified classes are invoked during the batch processing of the plurality of financial transactions;
generate mock classes for the identified classes that are invoked during the batch processing of the plurality of financial transactions;
create unit tests to perform unit testing of the identified classes that are invoked during the batch processing of the plurality of financial transactions, the unit tests configured to invoke the mock classes and use the default values for unit testing of the identified classes; and
output the unit tests.
14 . The system of claim 13 , wherein the identified classes invoked in the Java source code include Java framework classes, and wherein generating the mock classes includes generating mock classes for the Java framework classes with use of one or more mocking framework classes.
15 . The system of claim 13 , wherein the identified classes invoked in the Java source code include respective methods and constructors, and wherein the unit tests are configured to invoke the respective methods and constructors.
16 . The system of claim 13 , the memory further comprising instructions that, when executed by the at least one processor, cause the at least one processor to perform operations to:
cause the at least one processor to execute the unit tests and invoke one or more unit testing framework classes; and
provide results based on execution of the unit tests.
17 . The system of claim 16 , wherein the identified classes that are invoked are identified based on respective classes included in a Java Archive (JAR) package file;
wherein to create the unit tests includes replicating contents of the package file for the respective classes;
wherein the execution of the unit tests includes use of the replicated contents of the package file for the respective classes; and
wherein to provide the results from the execution of the unit tests includes to provide information relating to a usage of the generated mock classes by the execution of the unit tests.