Topic G + H - JavaDoc / Unit Testing

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/30

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

31 Terms

1
New cards

why should you document programs?

to make it easy to understand for other engineers who may want to reuse/update/maintain the program

2
New cards

what should you document with JavaDoc

  • interface

    • syntactic interface → structure and form of a method (i.e., the method signature)

    • semantic interface → meaning and behaviour (i.e., explanation of what a method does)

    • general internal working of a system

3
New cards

why should you use JavaDoc specifically to document programs/source codes?

  • to combine source code with documentaton (documentation is basically like when you comment your code to explain what each component means and does) and other reference materials

  • to make it easier to ensure that the documentation and code are in sync

  • to generate API specifications (or interface specifications) from source code (i.e., a description of the operations that an interface provides, how to call them, what inputs they accept, what outputs their produce, and any constraints/rules on their behaviour)

4
New cards

how do you make a special JavaDoc comment on your source code?

  • attach documentation comments (or doc comments) to classes, fields, and methods in your source code using the opening /** and the closing */

  • use a tool, called javadoc, to automatically generate HTML pages from source code

5
New cards
<p>explain what’s happening in the source code example</p>

explain what’s happening in the source code example

every comment framed by “/** [insert documentation comment] */” gets put in a HTML page (see image)

<p>every comment framed by “/** [insert documentation comment] */”  gets put in a HTML page (see image) </p>
6
New cards

how to write and format documentation comments

knowt flashcard image
7
New cards

what is a “javadoc tag”

a special keyword recognized by the javadoc tool and will be specially formatted in the HTML page

8
New cards

common javadoc tags

knowt flashcard image
9
New cards
<p>what would the HTML page look like for this documentation comment</p>

what would the HTML page look like for this documentation comment

knowt flashcard image
10
New cards

how to link to other features of the program using javadoc comments

example:

@see Dictionary#lookup(String) → links to the method “lookup(String)” in the class “Dictionary”

<p>example:</p><p>@see Dictionary#lookup(String) → links to the method “lookup(String)” in the class “Dictionary”</p>
11
New cards

what would linking to other features using javadoc look like in the HTML page

knowt flashcard image
12
New cards

how to link to existing API specifications using javadoc

knowt flashcard image
13
New cards

what does “testing” mean in terms of software engineering?

a process of showing that a program works for certain inputs

14
New cards

what are the phases of testing in software development?

  1. unit testing → to test each module/unit/component independently, usually done by the developers of the code

  2. integration and system testing → to test the system as a whole and everything works in harmony, usually done by separate testing or QA (quality assurance) team

  3. acceptance testing → to validate system functions for users and customers

15
New cards

what is unit testing?

  • testing the smallest, base units of code (such as methods, classes, procedures, subroutines/subprograms)

  • component is tested IN ISOLATION from the rest of the system and in a controlled environment

  • unit testing is often the target of testing applications such as JUnit

16
New cards

what is considered a “unit” in java

a class or interface or a set of them (e.g., an interface and 3 classes that implement it, or a public class along w/ its helper classes)

17
New cards

why should you do unit testing?

  • code must be tested to ensure that it is functional (the most barebones way to do this is to use the print statement)

  • unit testing is the epitome of the “divide and conquer approach,” which is where you split complex systems into manageable units and debug units individually; this method allows you to narrow down where bugs can be

18
New cards

how to do incorporate unit testing in the development of a system

  • build systems in layers

  • start with foundational classes that don’t depend on other classes

  • continuously test those classes before you build onto them (to ensure they are functional and reliable) and make classes that depend on them

19
New cards
<p>conventional testing without JUnit: what would be the output of this? why is this insufficient for unit testing?</p>

conventional testing without JUnit: what would be the output of this? why is this insufficient for unit testing?

  • see the output in the image

  • this is insufficient because you don’t have a organized comparison to what the EXPECTED outputs are, which is where JUnit comes in handy

<ul><li><p>see the output in the image</p></li><li><p>this is insufficient because you don’t have a organized comparison to what the EXPECTED outputs are, which is where JUnit comes in handy </p></li></ul><p></p>
20
New cards

what is the solution to shortcomings of conventional barebones testing with the print method?

automatic verification by a testing program

  • you can write a test program (a separate code file that’s specifically for running test cases)

  • OR use a testing tool such as JUNIT

21
New cards

example of testing the Math.sqrt(int) method with JUnit

the most important thing to note:

  • the “assertEquals” method works like this:

  • given assertEquals(a,b): a = EXPECTED OUTPUT, b = ACTUAL OUTPUT given by the method that you are testing

<p>the most important thing to note:</p><ul><li><p>the “assertEquals” method works like this:</p></li><li><p>given assertEquals(a,b): a = EXPECTED OUTPUT, b = ACTUAL OUTPUT given by the method that you are testing</p></li></ul><p></p>
22
New cards

naming convention for test files (for when you are doing unit testing)

<p></p><p></p>
23
New cards

assertion methods provided by JUnit

(this is also in the cheat sheet)

<p>(this is also in the cheat sheet)</p>
24
New cards

three main parts of test code

  1. test fixture

  2. test driver

  3. test oracle

25
New cards

test fixture (one of the three main part of test code)

the fixed, prepared setup of objects and data that a test needs in order to run correctly.

26
New cards

test driver (one of the three main part of test code)

the class that runs the test cases; the code that sets up the test, calls the method being tested, and feeds it inputs

27
New cards

test oracle (one of the three main part of test code)

the code for a test data/case that determines success or failure for that test data/case (aka, the “assert” method)

28
New cards

how to set up test fixture in a test class

@Before and @After are for initializing the variables in the test fixture

<p>@Before and @After are for initializing the variables in the test fixture</p>
29
New cards

example of setting up text fixture using JUnit

“@Before” is very important

<p>“@Before” is very important</p>
30
New cards

test suite

a set of test methods (methods that run tests on your code) and other test suites

  • organizes tests that share significant commonalities into a larger test set

  • aids in automation of testing

31
New cards

example of test suite

knowt flashcard image