• 【笔记】Eclipse and Java for Total Beginners—004


    Lesson 04 – JUnit Testing in Eclipse, Part 1

    • Create test source folder
    • Create Person Test class
    • Run first JUnit test

    1. Scrapbook的优/缺点

    • Great for exploring new Java classes and trying commmands.
    • Does not let you automate testing

    2. Unit Testing的特点

    • Automated testing of all methods
    • Very valuable when making changes to code
    • Key element of agile software development
    • Unit testing support built-in to Eclipse

    3. 把test classes和application code放在不同的目录,好处易见。首先,为test classes创建一个文件夹

        Select Project / File / New / Source folder / test (Folder name) / Finish.

    4. 接下来,想把test classes放在和被测试的classes同一个package里,所以在test目录下创建一个同名的package。

        Select test / File / New / Package / org.totalbeginner.tutorial (name) / Finish .

    5. 接着,创建第1个JUnit test。

        选择刚创建的package / RC org.totalbeginner.tutorial / New / JUnit test cae / PersonTest (name) / Person (Class under test )/ Next / 勾选 Person, setName, setMaximumBooks.

    这里需要指定libray的路径。

    6. 指定library的路径

        方法1:Quick Fix

                  右击或Ctrl+1.

        方法2:RC TotalBeginner / Build Path / Configure Build path.. / Libraries / Add Library.

    7. 运行一下test。

        Run / Run As / JUnit Test.

    1 package org.totalbeginner.tutorial;
    2
    3  import junit.framework.TestCase;
    4
    5  public class PersonTest extends TestCase {
    6
    7 public void testPerson() {
    8 fail("Not yet implemented");
    9 }
    10
    11 public void testSetName() {
    12 fail("Not yet implemented");
    13 }
    14
    15 public void testSetMaximumBooks() {
    16 fail("Not yet implemented");
    17 }
    18
    19 }

  • 相关阅读:
    [转] KVM I/O slowness on RHEL 6
    QEMU KVM libvirt 手册(3)
    QEMU KVM libvirt手册(2): monitor
    QEMU KVM libvirt 手册(1): 安装
    CentOS7下JSP连接Mysql
    使用Tomcat搭建基于域名的虚拟机
    CentOS7下搭建Tomcat服务器
    Nginx在线服务状态下平滑升级或新增模块
    源码安装LNMP
    二进制包安装Mysql
  • 原文地址:https://www.cnblogs.com/halflife/p/2076682.html
Copyright © 2020-2023  润新知