Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI-Assisted JUnit Testing

Java JUnit Maven AI assisted

Portfolio case study based on a Java/JPA university assignment: generate unit tests with one AI prompt, review the output, and organize the result into a runnable Maven test suite.

Project Idea

The original assignment implemented a small JPA model for a TOVAR table and three static methods:

  • Application.novyTovar(String nazov, Double cena)
  • Application.tovarBezCeny()
  • Application.odstranTovarBezCeny()

The AI task was to generate JUnit 4 tests that grade the solution from 0 to 10 points and verify persistence behavior, database constraints, duplicate handling, null prices, JPQL queries, and delete operations.

Repository Structure

Path Purpose
src/main/java/vsa/ Sanitized Java/JPA assignment solution
src/test/java/vsa/ Runnable Codex-generated JUnit 4 test suite
ai-generated/gemini/ Gemini-generated Java test outputs kept for comparison
ai-generated/chatgpt/ ChatGPT-generated Java test outputs kept for comparison
prompts/codex-prompt.md The one-prompt test-generation request
docs/assignment-summary.md Short summary of the original assignment
docs/test-results.md Captured test-result summary
docs/comparison.md Notes comparing the generated approaches

Run The Tests

Requirements:

  • Java 21
  • Maven 3.9+
mvn test

The Maven project uses an in-memory H2 database in PostgreSQL compatibility mode so the tests can run without a local PostgreSQL server.

Current verification:

  • mvn test passes locally with Java 21 and Maven 3.9.9.
  • The runnable Codex suite prints BODY = 10 for both ApplicationTest and ApplicationTestAlt.
  • EclipseLink may print expected warnings during constraint checks because the tests intentionally try invalid NULL and duplicate inserts.

What The Tests Check

  • A new product is persisted and receives an ID.
  • Duplicate product names return null instead of throwing.
  • NAZOV is unique and not nullable.
  • CENA can be null.
  • tovarBezCeny() returns all products without a price.
  • odstranTovarBezCeny() removes only products without a price.

Portfolio Value

This project shows more than "AI wrote tests." It demonstrates:

  • turning an assignment specification into testable requirements;
  • using AI as a test-generation assistant;
  • reviewing generated tests for coverage and correctness;
  • separating runnable tests from comparison artifacts;
  • documenting results and tradeoffs.

Raw submission archives, saved browser pages, account-related browser assets, and .docx logs are intentionally excluded.

About

AI-assisted JUnit 4 testing case study for a Java JPA assignment.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages