Topics
Important Points
SWE Testing
Developer testing
Developer testing is the testing done by the developers themselves as opposed to dedicated testers or end-users.
Testing Automation
A test driver is the code that ‘drives’ the SUT for the purpose of testing e.g., invoking the SUT with test inputs and verifying if the behavior is as expected.
Usually, we have a tool to do this test automation. In Java, we use JUnit.
Java JUnit
When writing JUnit tests for a class Foo, the common practice is to create a FooTest class, which will contain various test methods for testing methods of the Foo class.
Suppose we want to write tests for the IntPair class below.
public class IntPair {
int first;
int second;
public IntPair(int first, int second) {
this.first = first;
this.second = second;
}
/**
* Returns The result of applying integer division first/second.
* @throws Exception if second is 0.
*/
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).
Code Explanation
Each test method is marked with a
@Testannotation.Tests use
assertEquals(expected, actual)methods (provided by JUnit) to compare the expected output with the actual output. If they do not match, the test will fail.There are several ways to verify the code throws the correct exception. The second test method in the example above shows one of the simpler methods. If the exception is thrown, it will be caught and further verified inside the
catchblock. But if it is not thrown as expected, the test will reachfail()line and will fail as a result.
What to test for when writing test cases? This should be another module at NUS LOL. But for now, we can take it as the goal of these tests is to catch bugs in the code.
SWE Documentation
Developer-to-developer documentation can be in one of two forms:
Documentation for developer-as-user: This is to document how software componenets are to be used. Some examples are
API documentation
Tutorial-style instructional documentation
Documentation for developer-as-maintainer: This is to document how a system or a component is designed so that other developers can maintain and evolve that part of code.
SWE Design Models
Design is the creative process of transforming the problem into a solution; the solution is also called design. While modelling represents something else.
For example, a class diagram shown as follows is a model that represents a software design.

A model provides a simpler view of a complex entity because a model captures only a selected aspect.
For example, a class diagram captures the structure of the software design but not the behavior.
Multiple models of the same entity may be needed to capture it fully.
For example, in addition to a class diagram (or even multiple class diagrams), a number of other diagrams may be needed to capture various interesting aspects of the software.
SWE Class Diagrams Basics
UML Object Diagrams model object structures. UML Class Diagrams model class structures. Those rules that object structures need to follow can be illustrated as a class structure.
UML class diagrams describe the structure (but not the behavior) of an OOP solution. (You have already seen a class diagram from above). In this section, we will mainly touch the following:
Visibility
+ for public, - for private, # for protected and ~ for package private
There is no default visibility in UML. If a class diagram does not show the visibility of a member, it simply means the visibility is unspecified (for reasons such as the visibility not being decided yet or it being not important to the purpose of the diagram).
Association
Associations are the main connections among the classes in a class diagram.
Objects in an OO solution need to be connected to each other to form a network so that they can interact with each other. Such connections between objects are called associations.
Associations in an object structure can change over time.
Associations among objects can be generalized as associations between the corresponding classes too.
To implement associations, we use instance level variables. In other words, An association is a relationship resulting from one object keeping a reference to another object (e.g., storing an object in an instance variable). For example, the Course class can have a students variable to keep track of students associated with a particular course.
Associations as attributes
An association can be shown as an attribute instead of a line, and vice versa! The notation by default is as follows,
For example, the association that a Board has 100 Squares can be shown in either of these two ways:

Both is optional, which means we can use either one of them, but not both together!
In some cases, associations are better than attributes because they can show additional decorations such as association labels, association roles, multiplicity and navigability to add more information to a class diagram.
Association Class
To know what an association class in Java is, please read this part in advance. In a class diagram, association classes are denoted as a connection to an association link using a dashed line as shown below.

Navigability
When two classes are linked by an association, it does not necessarily mean both objects taking part in an instance of the association knows about (e.g., has a reference to) each other. The concept of navigability tells us if an object taking part in association knows about the other. In other words, it tells us if we can 'navigate' from the one object to the other in a given direction — because if the object 'knows' about the other, it has a reference to the other object, and we can use that reference to 'navigate to' (e.g., access) that other object.
Navigability can be unidirectional or bidirectional:
Unidirectional: If the navigability is from
AtoB, we sayawill have a reference tobbutbwill not have a reference toa.Bidirectional:
bwill have a reference toaandawill have a reference tob.
Two unidirectional associations in opposite directions do not add up to a single bidirectional association.
For example, the following code has two unidirectional associations between the Person class and the Cat class (in opposite directions). Because the breeder is not necessarily the same person keeping the cat as a pet, they are two separate associations, not a bidirectional association.
We use arrowheads to indicate the navigability of an association.

Multiplicity
Multiplicity is the aspect of an OOP solution that dictates how many objects take part in each association.
To implement the multiplicty, we have the following four types
We use the following notation to draw multiplicity in the class diagram.

Below are some 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 withinntominclusive e.g.,2..5,1..*(one or more),*..5(up to five)
There is no default multiplicity in UML. If a class diagram does not show the multiplicity of an association, it simply means the multiplicity is unspecified.
SWE Object Diagrams Basics
An object diagram shows an object structure at a given point of time and it can be used to complement class diagrams. For example, we can use object diagrams to model different object structures that can result from a design represented by a given class diagram.
Object Notation
The following is an example notation to represent an object.

Notes
Unlike classes, there is no compartment for methods.
Attributes compartment can be omitted if it is not relevant to the purpose of the diagram.
Object name can be omitted too e.g.,
:Carwhich is meant to say 'an unnamed instance of aCarobject'.
The following are examples of some acceptable object notations also.

Object diagrams vs. Class diagrams
Compared to the notation for class diagrams, object diagrams differ in the following ways:
Show objects instead of classes:
Instance name may be shown
There is a
:before the class nameInstance and class names are underlined
Methods are omitted
Multiplicities are omitted. Reason: an association line in an object diagram represents a connection to exactly one object (e.g., the multiplicity is always 1).
Furthermore, multiple object diagrams can correspond to a single class diagram.
When the class diagram has an inheritance relationship, the object diagram should show either an object of the parent class or the child class, but not both.
Association labels/roles can be omitted unless they add value.
Java Association Class
An association class represents additional information about an association. It is a normal class but plays a special role from a design point of view.
For example, a Man class and a Woman class are linked with a ‘married to’ association and there is a need to store the date of marriage. However, that data is related to the association rather than specifically owned by either the Man object or the Woman object. In such situations, an additional association class can be introduced, e.g., a Marriage class, to store such information.
Implement an association class
There is no special way to implement an association class. It can be implemented as a normal class that has variables to represent the endpoint of the association it represents.
Classic Questions
Association Class
Which of these are suitable as an Association Class? Note: the orange color class in the middle is the one being proposed as an association class.

(a)(b)(d)
Explanation: Mileage is a property of the car, and not specifically about the association between the Driver and the Car. If Mileage was defined as the total number of miles that car was driven by that driver, then it would be suitable as an association class.
Last updated









