【问题标题】:How to write mockito junit for the method below:如何为以下方法编写 mockito junit:
【发布时间】:2018-03-04 05:10:08
【问题描述】:

帮助

@Override
public String postRequestinTransactionService(String data) {
    RequestTransaction request = new RequestTransaction(data.getClass().getName(), data);
    HttpEntity<RequestTransaction> entity = new HttpEntity<RequestTransaction>(request);
    ResponseEntity<String> response = restTemplate.exchange(this.urlTransactions, HttpMethod.POST, entity,
            String.class);
    return response.getBody();
}

【问题讨论】:

  • 欢迎来到 SO。请访问 help center 并参观游览,了解询问的内容和方法。提示:邮政编码和努力!
  • 这是一个很琐碎的方法+测试,你到底卡在哪里了?
  • 测试的方法是什么

标签: java spring spring-mvc junit


【解决方案1】:

这是为您准备的准系统测试课程。您可以编写测试用例,如果您有特定问题,请提出问题。

    @RunWith(MockitoJUnitRunner.class)
    public class YourClassNameTest{

    @InjectMocks
    YourClassUnderTest myClass;
    private String data;

    @Before
    public void setUp() throws Exception {

    //prepare you data here
    // any other mock action you can set here
    }

    @Test
    public void testPostRequestinTransactionService() throws Exception {
    //Write you test here
    String result=myClass.postRequestinTransactionService(data);
    assertThat("result should be blablabla", result, is("blablabla");
    }

【讨论】:

  • 谢谢,但我已经有了,我的疑问是如何进行测试
猜你喜欢
  • 2018-05-15
  • 2015-08-30
  • 2019-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多