Skip to content

0.07_LLM_test_suite

Giuliano Ranauro edited this page Dec 3, 2024 · 1 revision

LLM generated test suite

Given the class TeamTest, we want to automatically generate a JUnit test suite that completely covers the methods from the class.

  1. Open Team.java in IntelliJ
  2. Open Copilot chat from the sidebar
  3. Entering the following prompt: scrivi una test suite con coverage 100% di team
  4. The answer from the LLM is the following:
TeamTest1
  1. We then proceed to copy the code into TeamTest.java.
  2. Execute JUnit test with coverage; the result is
Class Method Line Branch
100% 94% 91% 56%
  1. Since Branch coverage is not that good, we then proceed to enter a second prompt: il branch coverage è basso, sopratutto nel metodo equals(), alcuni branch non sono coperti. aggiungi dei casi di test per alzare la copertura sui branch.
  2. The output is the following:
TeamTest2
  1. I test vengono eseguiti nuovamente con coverage, ed il risultato è il seguente:
Class Method Line Branch
100% 94% 97% 100%
  1. Ora il coverage è soddisfacente.

Clone this wiki locally