qq_33414478 2017-04-01 01:12 采纳率: 9.1%
浏览 761
已采纳

java junit

请问怎么用 junut测试工具测试代码啊?

  • 写回答

1条回答 默认 最新

  • joy460154849 2017-04-01 03:21
    关注

    新建一个class,新建一个方法,加上Test注释,写完之后,run as junit Test
    给你举个例子吧:
    //实现图片的复制
    @Test
    public void testImgCopy() throws Exception{
    File f = new File("/Users/lixiuming/Desktop/商品详情图片/detail-1.jpg");
    FileInputStream fis = new FileInputStream(f);
    File out = new File("/Users/lixiuming/Desktop/project/day_15/detail-1.jpg");
    FileOutputStream fos = new FileOutputStream(out);
    byte[] b= new byte[1024];
    int len;
    while((len = fis.read(b)) != -1){
    fos.write(b, 0, len);
    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?