ZJU-ACES-ISE / chatunitest-core

A framework to generate unit tests using LLMs
MIT License
23 stars 6 forks source link

Wrong Logic which causes a loop #3

Closed jaykeerti closed 4 weeks ago

jaykeerti commented 1 month ago

https://github.com/ZJU-ACES-ISE/chatunitest-core/blob/79d741846c7a6bff66fa7fee6ba75c078e022f45/src/main/java/zju/cst/aces/api/Phase.java#L135

The logic here is wrong because the llm returns the entire class and it is checking for method correction which always returns false. then it moves on to repair and repeats the process

coder-chenzhi commented 1 month ago

@Mikekkkkk @cube-dragon

Mikekkkkk commented 1 month ago

@jaykeerti Actually, this is not a bug. The logic behind this is that LLM may return only a test method or a complete test class. For test methods, we will perform simple fixes to encapsulate them into a complete test class. If a test class is returned, we will directly perform ruleBasedRepair. This is a simple fix for LLM returning only a test method

jaykeerti commented 1 month ago

@Mikekkkkk Thanks for the response. The issue is the ruleBasedRepair prompt tells the llm to fix the unit test case, which in turn will return the entire class again instead of the method and the parser check keeps breaking.

I just tested for a simple java class as mentioned below. it does not successfully complete. it partially creates the test cases which wont run and the entire program breaks due to parser errors.

Can you please share if you have a working example

package com.llmtestgen.demo;

public class StringUtilsEqualsTest {

  public boolean test(String a, String b) {
    return a.equalsIgnoreCase(b);
  }
}
Mikekkkkk commented 1 month ago

@jaykeerti The ruleBasedRepair actually doesn't tell the llm to fix. The rulebasedRepair fixes will be applied to the tests output by LLM. The fixes here are simply changing the test class name, package, and adding imports.

@0verride
public String ruleBasedRepair(String code){
     code = changeTestName(code, promptConstructorImpl.getTestName());
     code = repairPackage(code, promptConstructorImpl.getPromptInfo().getclassInfo().getPackageName());
     code = repairImports(code, promptConstructorImpl.getPromptInfo().getclassInfo().getImports());
     return code
}

I think the fix you mentioned before is the later fix which is for the compile or runtime error caused by the generated test from llm. I try your case,it seems to work. image

Could you show me more details about your problems.

jaykeerti commented 1 month ago

@Mikekkkkk May I know how are you running this? maven or IintelliJ plugin?

Mikekkkkk commented 1 month ago

@jaykeerti i ran this with maven commands. If you want to run it with maven you can follow the steps in ReadME image By the way,you should keep the version consistent with your locally installed version. If you run it with plugin,you can follow this video https://www.youtube.com/watch?v=GmfxQUqm2ZQ

jaykeerti commented 4 weeks ago

Hey,

It worked as you mentioned. Thanks for the help. Great work.