如何为给定方法编写测试用例

米兰·波迪亚尔

我想为给定的方法编写一个测试用例

private String productCode;

public PaymentManager() {
    this.productCode = "SMART-TV;
}

@Override
public boolean isResponsibleFor(TransactionDetailResource resource) {
    return productCode.equals(resource.getProductCode());
}

如何为此方法编写测试用例

无情的

首先,创建一个测试类和一个测试函数

@Test
public void testIsResponsibleFor() {
...
}

(如果你使用的是Eclipse,你可以按Ctrl+J,它会自动为你创建测试类)

然后在您的测试函数中,您必须创建两个对象,一个 PaymentManager 和一个 TransactionDetailResource。

PaymentManager p = PaymentManager();
TransactionDetailResource t = TransactionDetailResource();
t.setProductCode("SMART-TV")

我假设您在 TransactionDetailResource 类中有一个 Setter。

AssertThat(p.isResponsibleFor(t),is(Boolean.True))

这是部分答案,但它可以为您提供一个起点

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何为 jQuery on() 方法编写 Jasmine 测试用例

如何为方法编写单元测试用例[Angular]

如何为抽象类方法编写测试用例

如何为线程运行方法编写junit测试用例

如何为 ProcessBuilder 编写测试用例

如何为BadRequest编写单元测试用例?

如何为CombineLatestrxjs Angular编写Jasmine Unit测试用例

如何为使用juid的uuid编写函数的测试用例?

如何为setInterval()函数编写测试用例

如何为Perl脚本编写单元测试用例

如何为CDI编写Junit测试用例?

如何为Android API编写单元测试用例?

如何为Thread类编写Junit测试用例

如何为我的函数编写测试用例?的PHP

如何为 spring boot 编写 Junit 测试用例:

如何为 GlobalExceptionHandler ControllerAdvice 编写 Spring boot 测试用例

如何为ExecuteNonQuery和ExecuteScalar和GetDataSet方法编写模拟单元测试用例

如何为公共静态方法编写茉莉花业力测试用例?

如何为无参数方法自动生成测试用例?

如何编写动态测试用例

如何编写此测试用例?

如何编写PowerMock测试用例?

如何编写注册帐户测试用例?

如何为此类编写一个junit测试用例

如何为以下代码编写带有例外的Junit测试用例?

如何为junit中的字符串数组输入编写测试用例?

如何为实现ApplicationListener <ApplicationPreparedEvent>的类编写JUNIT测试用例

如何为其余客户编写针对Webtarget和响应的Mock测试用例?

如何为Spring Boot应用程序编写Junit测试用例?