这是我要为其编写Junit测试用例的代码-

@GET

@Path("/get")

@Produces("application/json")

public User getUser()
{

    User user= new com.rest.rahul.User();

    user.setEmpid("12");
    user.setEmail("DJ@gmail.com");
    user.setName("DJ");
    return user;

}

最佳答案

您要对什么进行单元测试?我不会为简单的二传手而烦恼。但是,如果要测试JSON输出,则实际上是在寻找集成测试之类的东西。引导您的应用程序的测试,设置Web服务,然后调用getUser方法。
看看https://blog.codecentric.de/en/2012/05/writing-lightweight-rest-integration-tests-with-the-jersey-test-framework/

09-10 03:43
查看更多