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 }

  • 相关阅读:
    luogu1196 银河英雄传说 (并查集)
    [BZOJ2243][SDOI2011]染色
    [BZOJ1879] [Sdoi2009]Bill的挑战
    [Noip2003] 侦探推理
    [Noip2005] 篝火晚会
    [JZOJ100047] 【NOIP2017提高A组模拟7.14】基因变异
    [九省联考2018]一双木棋chess
    [Noip2009] 靶形数独
    [Luogu2737] [USACO4.1]麦香牛块Beef McNuggets
    [BZOJ3109] [cqoi2013]新数独
  • 原文地址:https://www.cnblogs.com/halflife/p/2076682.html
Copyright © 2011-2022 走看看