zoukankan      html  css  js  c++  java
  • 【笔记】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 }

  • 相关阅读:
    chkconfig命令
    Office 2010 与搜狗输入法兼容问题
    【转】WAS入门简介
    UTF8GB2312GBK
    System.getProperty
    Hibernate 事务方法保存clob类型数据
    Eclipse 或者 Myeclipse 提示选择工作空间设置
    request
    那些操蛋的人生
    Java新手入门很重要的几个基本概念
  • 原文地址:https://www.cnblogs.com/halflife/p/2076682.html
Copyright © 2011-2022 走看看