如何在lombok中为@AllArgsConstructor编写Junit测试用例

yrdbyhpb  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(141)

如何在lombok中为@AllArgsConstructor编写测试用例。有谁能帮我解决这个问题吗?

@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ABC{
    private Integer A;
    private String B;
    private BigDecimal c;
    private BigDecimal d;
    private String e;
    private String f;
    private String g;
}
vfh0ocws

vfh0ocws1#

使用所有参数创建一个示例将得到一个结果:

public class ABCTest {
    
        @Test
        public void testAllArgsConstructor() {
        ABC abc = new ABC(1, "test", new BigDecimal("10.5"), new 
        BigDecimal("20.5"), "example", "sample", "data");
        assertNotNull(abc);
    
        }
    }

或者为每个值创建变量:

public class ABCTest {

    @Test
    public void testAllArgsConstructor() {
        Integer a = 1;
        String b = "test";
        BigDecimal c = new BigDecimal("10.5");
        BigDecimal d = new BigDecimal("20.5");
        String e = "example";
        String f = "sample";
        String g = "data";

        ABC abc = new ABC(a, b, c, d, e, f, g);

        assertNotNull(abc);

    }
}

如果你添加get方法,你将能够检查等于添加到测试中,如:

assertEquals(a, abc.getA());
assertEquals(b, abc.getB());
assertEquals(c, abc.getC());
assertEquals(d, abc.getD());
assertEquals(e, abc.getE());
assertEquals(f, abc.getF());
assertEquals(g, abc.getG());

相关问题