Kate Lo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Week 8 ## Developer Testing - **Developer testing is the testing done by the developers themselves** as opposed to professional testers or end-users. - Delaying testing until the full product is complete has a number of disadvantages: - **Locating the cause of such a test case failure is difficult due to a large search space**. - **Fixing a bug found during such testing could result in major rework**, especially if the bug originated during the design or during requirements specification. - **One bug might 'hide' other bugs**, which could emerge only after the first bug is fixed. - **The delivery may have to be delayed** if too many bugs were found during testing. ![](https://i.imgur.com/VJKGcjS.png =60%x) - **A test driver is the code that ‘drives’ the SUT(Software Under Test) for the purpose of testing** i.e. invoking the SUT with test inputs and verifying the behavior is as expected. > PayrollTest ‘drives’ the Payroll class by sending it test inputs and verifies if the output is as expected. ```java= public class PayrollTestDriver { public static void main(String[] args) throws Exception { //test setup Payroll p = new Payroll(); //test case 1 p.setEmployees(new String[]{"E001", "E002"}); // automatically verify the response if (p.totalSalary() != 6400) { throw new Error("case 1 failed "); } //test case 2 p.setEmployees(new String[]{"E001"}); if (p.totalSalary() != 2300) { throw new Error("case 2 failed "); } //more tests... System.out.println("All tests passed"); } } ``` > This an automated test for a Payroll class, written using JUnit libraries. ```java= @Test public void testTotalSalary(){ Payroll p = new Payroll(); //test case 1 p.setEmployees(new String[]{"E001", "E002"}); assertEquals(6400, p.totalSalary()); //test case 2 p.setEmployees(new String[]{"E001"}); assertEquals(2300, p.totalSalary()); //more tests... } ``` > Suppose we want to write tests for the IntPair class below. ```java= public class IntPair { int first; int second; public IntPair(int first, int second) { this.first = first; this.second = second; } public int intDivision() throws Exception { if (second == 0){ throw new Exception("Divisor is zero"); } return first/second; } @Override public String toString() { return first + "," + second; } } ``` > Here's a IntPairTest class to match (using JUnit 5). ```java= import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; public class IntPairTest { @Test public void testStringConversion() { assertEquals("4,7", new IntPair(4, 7).toString()); } @Test public void intDivision_nonZeroDivisor_success() throws Exception { assertEquals(2, new IntPair(4, 2).intDivision()); assertEquals(0, new IntPair(1, 2).intDivision()); assertEquals(0, new IntPair(0, 5).intDivision()); } @Test public void intDivision_zeroDivisor_exceptionThrown() { try { assertEquals(0, new IntPair(1, 0).intDivision()); fail(); // the test should not reach this line } catch (Exception e) { assertEquals("Divisor is zero", e.getMessage()); } } } ``` - Note: - Each test method is marked with a **`@Test`** annotation. - Tests use **`Assert.assertEquals(expected, actual)`** methods to compare the expected output with the actual output. If they do not match, the test will fail. JUnit comes with other similar methods such as **`Assert.assertNull`** and **`Assert.assertTrue`**. - Java code normally use **camelCase** for method names e.g., `testStringConversion` but when writing test methods, sometimes another convention is used: `whatIsBeingTested_descriptionOfTestInputs_expectedOutcome` e.g., `intDivision_zeroDivisor_exceptionThrown` ## Writing Developer Documents 1. **Documentation for developer-as-user**: Software components are written by developers and reused by other developers, which means there is a need to document how such components are to be used. Such documentation can take several forms: - **API** documentation: APIs expose functionality in small-sized, independent and easy-to-use chunks, each of which can be documented systematically. - **Tutorial-style** instructional documentation: In addition to explaining functions/methods independently, some higher-level explanations of how to use an API can be useful. 2. **Documentation for developer-as-maintainer**: There is a need to document how a system or a component is designed, implemented and tested so that other developers can maintain and evolve the code. Writing documentation of this type is **harder because of the need to explain complex internal details**. However, given that readers of this type of documentation usually have access to the source code itself, only some information need to be included in the documentation, as code (and code comments) can also serve as a complementary source of information. - TUTORIALS: is learning-oriented allows the newcomer to get started is a lesson Analogy: teaching a small child how to cook - HOW-TO GUIDES: is goal-oriented shows how to solve a specific problem is a series of steps Analogy: a recipe in a cookery book - EXPLANATION: is understanding-oriented explains provides background and context Analogy: an article on culinary social history - REFERENCE: is information-oriented describes the machinery is accurate and complete Analogy: a reference encyclopedia article - **Software documentation is best kept in a text format**, for the ease of version tracking. A writer friendly source format is also desirable as non-programmers (e.g., technical writers) may need to author/edit such documents. As a result, formats such as Markdown, Asciidoc, and PlantUML are often used for software documentation. ## Design: Models - two main aspects: - **Product/external design: designing the external behavior of the product to meet the users' requirements.** This is usually done by product designers with the input from business analysts, user experience experts, user representatives, etc. - **Implementation/internal design: designing how the product will be implemented to meet the required external behavior.** This is usually done by software architects and software engineers. - A model provides a simpler view of a complex entity because a model captures only a selected aspect. ## Class/Object Diagrams: Basics - Object structures within the same software can change over time. - However, object structures do not change at random; they change based on a set of rules, as was decided by the designer of that software. Those rules that **object structures need to follow can be illustrated as a class structure** i.e. a structure that exists among the relevant classes. ### Class Diagrams - **UML class diagrams describe the structure (but not the behavior) of an OOP solution.** ![](https://i.imgur.com/rjrxVAF.png =70%x) - The basic UML notations used to represent a class: ![](https://i.imgur.com/lNaXCEO.png =60%x) - **The 'Operations' compartment and/or the 'Attributes' compartment may be omitted** if such details are not important for the task at hand. 'Attributes' always appear above the 'Operations' compartment. All operations should be in one compartment rather than each operation in a separate compartment. Same goes for attributes. ![](https://i.imgur.com/3sKyxTk.png =90%x) - The visibility of attributes and operations is used to indicate **the level of access allowed for each attribute or operation**. The types of visibility and their exact meanings depend on the programming language used. Here are some common visibilities and how they are indicated in a class diagram: `+` : public `-` : private `#` : protected `~` : package private - In UML class diagrams, **underlines denote class-level attributes and variables.** ![](https://i.imgur.com/z3Wd7RS.png =23%x) - **Associations are the main connections among the classes in a class diagram.** - We use a solid line to show an association between two classes. #### Labels - **Association labels describe the meaning of the association**. The arrow head indicates the **direction** in which the label is to be read. ![](https://i.imgur.com/PN6oa5k.png =70%x) - Diagram on the left: Admin class is associated with Student class because an Admin object uses a Student object. - Diagram on the right: Admin class is associated with Student class because a Student object is used by an Admin object. #### Roles - **Association Role labels are used to indicate the role played by the classes in the association.** ![](https://i.imgur.com/whfBHKa.png =40%x) -This association represents a marriage between a Man object and a Woman object. The respective roles played by objects of these two classes are husband and wife. ```java= class Man{ Woman wife; } class Woman{ Man husband; } ``` #### Multiplicity - Multiplicity is the aspect of an OOP solution that **dictates how many objects take part in each association**. ##### Implementing multiplicity - **A normal instance-level variable gives us a `0..1` multiplicity** (also called optional associations) because a variable can hold a reference to a single object or `null`. - **Bi-directional associations require matching variables in both classes.** ```java= class Foo { Bar bar; //... } class Bar { Foo foo; //... } ``` - **To implement other multiplicities, choose a suitable data structure** such as Arrays, ArrayLists, HashMaps, Sets, etc. - Commonly used multiplicities: `0..1` : optional, can be linked to 0 or 1 objects `1` : compulsory, must be linked to one object at all times. `*` : can be linked to 0 or more objects. `n..m` : the number of linked objects must be n to m inclusive ![](https://i.imgur.com/ToAN8E5.png =35%x) #### Navigability - The concept of which **class in the association knows about the other class** is called navigability. - We **use arrow heads** to indication the navigability of an association. > `Logic` is aware of `Minefield`, but `Minefield` is not aware of `Logic` ![](https://i.imgur.com/1KOFVCv.png =35%x) ```java= class Logic{ Minefield minefield; } class Minefield{ ... } ``` - **Navigability can be shown in class diagrams as well as object diagrams.** ### Object Diagrams - **An object diagram shows an object structure at a given point of time.** ![](https://i.imgur.com/GUO5eBr.png =70%x) - Notes: - The class name and object name e.g. `car1:Car` are **underlined**. - `objectName:ClassName` is meant to say 'an instance of `ClassName` identified as `objectName`'. - Unlike classes, there is **no compartment for methods**. - Attributes compartment can be omitted if it is not relevant to the task at hand. - Object name can be omitted too e.g. :Car which is meant to say 'an unnamed instance of a Car object'. ### Associations as Attributes - **An association can be shown as an attribute instead of a line.** **`name: type [multiplicity] = default value`** > A `Piece` may or may not be on a `Square`. Note how that association can be replaced by an `isOn` attribute of the `Piece` class. The `isOn` attribute can either be `null` or hold a reference to a `Square` object, matching the `0..1` multiplicity of the association it replaces. The default value is `null` ![](https://i.imgur.com/p2Fsyoc.png) > The association that a `Board` has 100 `Square`s can be shown in either of these two ways: ![](https://i.imgur.com/bGjFWHM.png =80%x) ### Notes - **UML notes can augment UML diagrams with additional information.** These notes can be shown connected to a particular element in the diagram or can be shown without a connection. ![](https://i.imgur.com/DFy2Zp8.png =60%x) ## Project Mgt: Scheduling and Tracking - A **milestone** is the end of a stage which **indicates a significant progress.** - Each **intermediate product release** is a milestone. ### Buffer - **A buffer is a time set aside to absorb any unforeseen delays.** - **Do not inflate task estimates to create hidden buffers**; have explicit buffers instead. ![](https://i.imgur.com/AjS934j.png =80%x) ### Issue tracker - Issue trackers (sometimes called bug trackers) are commonly used to **track task assignment and progress.** ### Work Breakdown Structure - A Work Breakdown Structure (WBS) **depicts information about tasks and their details in terms of subtasks.** When managing projects it is useful to divide the total work into smaller, well-defined units. Relatively complex tasks can be further split into subtasks. In complex projects a WBS can also include prerequisite tasks and effort estimates for each task. ![](https://i.imgur.com/HjMTm73.png =50%x) - The effort is traditionally measured in man **hour/day/month**

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully