//被测试方法 private Double format(Double fileSize){ Double size = fileSize; size = size / 1024 / 1024; size = (int)(size.doubleValue() * 10 + 0.5) / 10.0; return size; } @Test public void testFormat(){ ClientDownloadAction action = new ClientDownloadAction(); double size = 3732930; Class class1 = action.getClass(); try { Method format = class1.getDeclaredMethod("format", Double.class); format.setAccessible(true);//设为可见 Double result = (Double)format.invoke(action, size); Double expect = 3.6; Assert.assertEquals(expect, result); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } |