zoukankan      html  css  js  c++  java
  • 【笔记】Eclipse and Java for Total Beginners—007

    Lesson 07 – Create Book Class

    • Create BookTest before creating Book class
    • Test Book constructor
    • Create get and set methods

    1. 新建一个JUnit test case, name为BookTest, Class under test为空,因为尚未建Book class.

    2. 建立Book class, 注意目录为src。

    3. Test-first approach to Book class

    • Create BookTest class.
    • Create testBook() method to test constructor.
    • Used Eclipse Quick Fix to correct compiler errors.
    • Coded constructor in Book class.
    • Ran and passed JUnit test.
    1 package org.totalbeginner.tutorial;
    2
    3  import junit.framework.TestCase;
    4
    5  public class BookTest extends TestCase {
    6
    7 public void testBook() {
    8 Book b1 = new Book("Great Expectations");
    9 assertEquals("Great Expectations", b1.title);
    10 assertEquals("unknown author", b1.author);
    11 }
    12
    13 }
    1 package org.totalbeginner.tutorial;
    2
    3  public class Book {
    4
    5 public String title;
    6 public String author;
    7
    8 public Book(String string) {
    9 this.title = string;
    10 this.author = "unknown author";
    11 }
    12
    13 public String getAuthor() {
    14 return author;
    15 }
    16
    17 public void setAuthor(String author) {
    18 this.author = author;
    19 }
    20
    21 public String getTitle() {
    22 return title;
    23 }
    24
    25 }
  • 相关阅读:
    Java Web学习笔记---用GET实现搜索引擎
    Docker之docker log详解
    Docker之save、load、export、import命令
    Docker之镜像地址
    GIT使用详解
    Docker之commit制作镜像
    Python之sys.arg[]的用法解释
    python常用内置函数
    VBA精彩代码分享-1
    C#读写EXCEL单元格的问题
  • 原文地址:https://www.cnblogs.com/halflife/p/2077778.html
Copyright © 2011-2022 走看看