英文:
How to write a JUnit test for Base64.decodeBase64
问题
以下是我想要编写 Junit 测试用例的方法:
public static byte[] getDecodeBase64(JSONObject object,String key) {
return Base64.decodeBase64(object.getString(key));
}
我编写了如下测试:
@Test
public void testGetDecodeBase64(){
JSONObject test = new JSONObject();
test.put("clientId", "test");
String value = "[B@[2807bdeb]";
assertEquals(value, JSONUtil.getDecodeBase64(test, "clientId").toString());
}
但每次该方法返回的值都不同。
英文:
Below is my method for which i want to write Junit test case:
public static byte[] getDecodeBase64(JSONObject object,String key) {
return Base64.decodeBase64(object.getString(key));
}
I wrote this:
@Test
public void testGetDecodeBase64(){
JSONObject test = new JSONObject();
test.put("clientId", "test");
String value = "[B@[2807bdeb]";
assertEquals(value, JSONUtil.getDecodeBase64(test, "clientId").toString());
}
But each time the value returned by the method is different.
答案1
得分: 1
数组的toString方法返回一个表示数组标识的字符串。
英文:
toString method of an array returns a string representing the Id of the array.
答案2
得分: 0
你应该使用 assertArrayEquals
来检查数组中的内容。
或者,如果你想要测试字符串,可以将字节数组转换为字符串:
byte[] bytes = {...}
String str = new String(bytes, "UTF-8");
英文:
You should use assertArrayEquals
to check what's in the array.
Or, if you want to test with String, to convert your byte array into a String with :
byte[] bytes = {...}
String str = new String(bytes, "UTF-8");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论