Skip to main content

AI-Driven Unit Test Generation for Java

Project description

JavaTestGenie

MIT License PyPI

Installation

pip install java-test-genie

Usage

Before running genie, set your OpenAI API key with export OPENAI_API_KEY=<API-KEY-HERE>. You can obtain it at https://platform.openai.com/account/api-keys

Ensure that you are in a at the same level with src/ when running the tool.

You need to create a config file named .genie.json within your java repository. This file should be at the same level with src/ as well as where you will run genie. In this file, you can specify which directories & files to include and exclude. The example below includes the service/ directory but excludes service/interface. Similarly, you can specify file names.

{
  "include": [
    {
      "parent_dir": "src/main/java/com/ase/restservice",
      "dir_names": ["service"],
      "file_names": []
    }
  ],
  "exclude": [
    {
      "parent_dir": "src/main/java/com/ase/restservice/service",
      "dir_names": ["interface"],
      "file_names": []
    }
  ]
}

The file is case-sensitive. Ensure that you do not list files in the "exclude" section unless they match a path in the "include" section. Excluding a path will delete all matches, even if a specific class is explicitly listed in the "include" section. For instance, if you exclude "model/" but include "model/Account.java", it will not work. Instead, simply include "model/Account.java" and leave the "exclude" section empty, as the "model/" directory is already skipped.

Finally, you can run it with:

genie

Example

Here is an example repo that you can use the config file above with.

git clone https://github.com/boraelci/kaiserschmarrn.git

Grammar

Parsing Java files with the Tree-sitter library requires grammar files. They were obtained in the following way for this tool.

For macOS

git clone https://github.com/tree-sitter/tree-sitter-java.git
cd tree-sitter-java
tree-sitter generate
gcc -shared -o libtree-sitter-java.dylib -Isrc src/parser.c

For Windows

Used the one provided as java-grammar.so

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

java-test-genie-0.1.1.tar.gz (2.3 MB view details)

Uploaded Source

File details

Details for the file java-test-genie-0.1.1.tar.gz.

File metadata

  • Download URL: java-test-genie-0.1.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for java-test-genie-0.1.1.tar.gz
Algorithm Hash digest
SHA256 49a7a4ee5280d786b5db6dbeefb52db45b868439a22ca3e81f643cfa859f6018
MD5 1122cb92a21299de8fceded8859feacd
BLAKE2b-256 33fcc4a8984c4e99eb8817762ef8a25c779add40459ee941c8d80b1de6ec2665

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page