Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAVA]null value in unit test case code #12494

Open
ClayGminx opened this issue Nov 26, 2024 · 3 comments
Open

[JAVA]null value in unit test case code #12494

ClayGminx opened this issue Nov 26, 2024 · 3 comments

Comments

@ClayGminx
Copy link

ClayGminx commented Nov 26, 2024

issue in English

Summary

I try to generate code by following command,

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i https://petstore.swagger.io/v2/swagger.json \
  -l java \
  -o samples/client/petstore/java

When it done, I open PetApiTest.java, then I saw a piece of test case code,

@Test
public void addPetTest() throws Exception {
    Pet body = null;
    api.addPet(body);

    // TODO: test validations
}

Now, my issue is that I hope the body value shouldn't be null, and I hope the TODO should be completed.

Swagger-codegen version

2.4.43

Suggest a fix/enhancement

It is expected that the unit test code is complete, that is, it can create and initialize different objects, and make assertions.

Additional information: I'm working in a test technology team that provide technology for test engineer. Due to the rise of AI technology, especially the LLM like ChatGPT, my manager wants to introduce the technology to resolve some problems. Now he wants to input a JSON file written in OpenAPI Specification like swagger.json to a tool, then hope that the tool can produce some request data which can be used for calling RESTful API.

Okay. That's all, thank you.

issue in Chinese

Because I'm Chinese, I remain my Chinese issue.

问题概述

我尝试按以下命令生成代码,

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i https://petstore.swagger.io/v2/swagger.json \
  -l java \
  -o samples/client/petstore/java

生成后,我打开PetApiTest.java,看到其中一个测试用例:

@Test
public void addPetTest() throws Exception {
    Pet body = null;
    api.addPet(body);

    // TODO: test validations
}

现在问题是,我希望body值不是null,并且希望TODO代码已经自动写好了。

Swagger-codegen version

2.4.43

Suggest a fix/enhancement

希望单元测试代码是完全的,也就是能够创建和初始化不同的对象,并且做出断言。

@micryc
Copy link
Contributor

micryc commented Dec 2, 2024

Hi @ClayGminx could you translate issue to English ? That would be really helpful 😃

@ClayGminx ClayGminx changed the title [JAVA]单元测试代码中用null初始化对象变量 [JAVA]null value in unit test case code Dec 3, 2024
@ClayGminx
Copy link
Author

Hi @ClayGminx could you translate issue to English ? That would be really helpful 😃

Sure, I can.

@ponelat
Copy link
Member

ponelat commented Dec 10, 2024

@ClayGminx this would be a feature request, there can be different tests and ways that we should test a generated SDK client. We'd welcome any efforts here, but at this point it isn't within scope for the team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants