软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

时间:2025-02-08 10:03:20

小镓自述Eclipse使用及自动单元测试技术

因为本人对JAVA有一些兴趣,所以就决定用Eclipse来完成这次作业,从安装Eclipse到学习写代码,最后学会用Junit来进行单元测试。这段过程给我打开了一个新的大门,收获颇丰!

下载JAVA开发工具

  • 1.点开Eclipse的官网,并下载。

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 2.解压并安装JAVA环境

接下来按照图片选择:

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 3.配置环境变量

    单击“计算机-属性-高级系统设置”,单击“环境变量”。在“系统变量”栏下单击“新建”,创建新的系统环境变量。
    编辑->变量名"Path",在原变量值的最后面加上 ;D:\JAVA\bin;D:\JAVA\jre\bin
    新建->变量名“CLASSPATH”,变量值 ;D:\JAVA\lib;D:\JAVA\lib\dt.jar;D:\JAVA\lib\tools.jar
    两个路径直接复制进去就可以啦!具体如下图:

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 4.确认环境配置是否正确

    在主页搜索中寻找“cmd”控制台。
    在控制台分别输入java,javac,java -version 命令:

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

这三个都一样的话,恭喜,java你已经成功安装了!
为了便于以后运行,建议添加一个桌面快捷方式!

学习并使用JAVA写代码和自动单元测试技术

  • 1.自学写了一个小程序,就是用来求两个数中的最大值。

    代码如下:

    package dog;
    //求两个数中的最大值
    public class SubArray {
    public int max(int x,int y){
    if(x > y)
    return x;
    else
    return y;
    }
    }

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 2.学习写自动单元测试

    代码如下:

    package dog.test;
    import dog.SubArray;
    import junit.framework.TestCase;
    public class TestMaximun extends TestCase{
    public void testMax(){
    int x = 1;
    int y = 2;
    int z = -1;
    SubArray sub = new SubArray();
    int result1 = sub.max(x,y);
    int result2 = sub.max(y,x);
    int result3 = sub.max(z,x);
    assertTrue(result1 == y);
    assertTrue(result2 == y);
    assertTrue(result3 == 1);
    }
    }

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 3.JAVA中使用Junit的方式:

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

  • 4.测试结果

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

软件工程第二次作业(One who wants to wear the crown, Bears the crown.)

这次自己从安装到简单的使用都由自己完成,大大提高了我的自学能力,也感觉只要认真什么都可以做到,通过这次的学习我的JAVA也算是入了个小门,而且觉得JAVA的编程方式很有意思,越来越期待后面的作业了!


One who wants to wear the crown, Bears the crown.