• lab1--ideal + junit


    一、安装junit、hamcrest、eclemma

      笔者用的是ideal,file --> project structure 

    左边侧栏选择libraries,左第二侧栏选择“+”(java),依次把需要的junit,hamcrest的jar包和eclemma解压后的文件包添加

    二、编写判断三角形形状的代码

    src下再建一个package,里面写判断三角形形状的class,目录结构如下:

    判断的代码:

    public class Triangle {
        public  static String Shape(int a, int b,int c) {
            String shape = "";
            if ((a + b <= c) || (a + c <= b) || (b + c <= a) || (a <= 0) || (b <= 0) || (c <= 0)) {
                shape = "非三角形";
            }
            else if ((a == b) && (b == c)) {
                    shape = "等边三角形";
            }
            else if (((a == b) && (b != c)) || ((b == c) && (a != b)) || ((a == c) && (c != a))) {
                        shape = "等腰三角形";
            }
            else {
                        shape = "任意三角形";
            }
            return shape;
        }
    }
    

      三、生成测试用例

    新建一个test的文件夹存放测试用例:file --> new --> directory

    public class Triangle {
    }
    

      选中要生成测试的类Triangle,使用快捷键option+return,选择create test ,在test文件夹下会自动生成测试用例文件

    四、设计测试用例并执行

    public class TriangleTest {
    
        @Before
        public void setUp() throws Exception {
    
        }
    
        @After
        public void tearDown() throws Exception {
    
        }
    
        @Test
        public void testShape1() throws Exception {
            assertEquals((String)"非三角形",Triangle.Shape(2,2,4));
        }
    
        @Test
        public void testShape2() throws Exception {
            assertEquals((String)"非三角形",Triangle.Shape(2,2,5));
        }
    
        @Test
        public void testShape3() throws Exception {
            assertEquals((String)"非三角形",Triangle.Shape(-2,2,5));
        }
    
        @Test
        public void testShape4() throws Exception {
            assertEquals((String)"非三角形",Triangle.Shape(0,2,5));
        }
    
        @Test
        public void testShape5() throws Exception {
            assertEquals((String)"等边三角形",Triangle.Shape(2,2,2));
        }
    
        @Test
        public void testShape6() throws Exception {
            assertEquals((String)"等腰三角形",Triangle.Shape(2,2,3));
        }
    
        @Test
        public void testShape7() throws Exception {
            assertEquals((String)"任意三角形",Triangle.Shape(2,3,4));
        }
    
    }
    

      五、执行结果

  • 相关阅读:
    微信小程序代码大全
    【活动发布】捷微H5-微信新年砍价活动,开源发布了
    小程序官网CMS开源项目出炉,Weixin-App-CMS 1.0 版本正式发布
    jeecg开源项目的IDEA的部署
    1024程序员节宅男节日快乐 -- JAVA快速开发平台,JEECG 3.8宅男优化版本发布
    微信小程序商城开源项目,Weixin-App-Shop 1.0 版本正式发布!!!
    JEECG-Swagger UI的使用说明
    JEECG 上传插件升级-代码生成器
    Why 0.1 + 0.2 === 0.30000000000000004 ?
    linux (一)
  • 原文地址:https://www.cnblogs.com/shangcong/p/5292590.html
Copyright © 2020-2023  润新知