博客
关于我
Java环境配置及eclipse单元测试
阅读量:284 次
发布时间:2019-03-03

本文共 1274 字,大约阅读时间需要 4 分钟。

安装Eclipse并创建Junit测试项目

安装Eclipse

  • 下载Eclipse
  • 解压Eclipse到合适的文件夹(注意:不要解压到中文路径下)
  • 配置环境变量

  • 右键"我的电脑",选择"属性",在高级系统设置中找到环境变量。
  • 新建系统变量"CLASSPATH",值为:.;D:\Program Files\Java\jdk1.8.0_73\lib;
  • 新建系统变量"JAVA_HOME",值为:D:\Program Files\Java\jdk1.8.0_73;
  • 编辑系统变量"PATH",在值中添加D:\Program Files\Java\jdk1.8.0_73\bin;注意前面要加英文的";"
  • 添加Junit库

  • 右键项目名称,选择"Properties",在Java Build Path中选择Libraries,添加Junit库
  • 确认添加成功
  • 创建测试项目

  • 右键项目名称,选择"New",然后选择"Others",再选择"Junit Test Case"
  • 填写测试名称,勾选setUp方法,选择被测试类和方法
  • 编写测试代码

    package softwareEngineering;import static org.junit.Assert.*;import java.util.Scanner;import org.junit.Before;import org.junit.Test;public class TestUnit01 {    private MaximumSubarray T_maxsum;    private int[] T_vc;    private static final int n=5;    private Scanner sc;    @Before    public void setUp() throws Exception {        T_maxsum = new MaximumSubarray();        T_vc = new int[n];        sc = new Scanner(System.in);        for (int i = 0; i < n; i++) {            T_vc[i] = (Integer) sc.nextInt();        }    }    @Test    public void testFindMaximumSubarray() {        int res = T_maxsum.findMaximumSubarray(n, T_vc);        assertEquals(-1, res);    }}

    运行测试

  • 右键项目,选择"Run as",然后选择"JUnit Test"
  • 输入测试数据并运行测试
  • 测试结果

    通过以上步骤,您已经完成了Eclipse的安装、环境配置以及创建并运行了Junit测试项目。如果在测试过程中遇到问题,请确保 JDK版本正确,并检查路径配置是否准确。

    转载地址:http://yqnl.baihongyu.com/

    你可能感兴趣的文章
    notepad++正则表达式替换字符串详解
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notes on Paul Irish's "Things I learned from the jQuery source" casts
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>