0% found this document useful (0 votes)
34 views13 pages

Lab 01

The document outlines the tasks for SENG275 Lab 1, which includes installing necessary software such as Microsoft Teams, Java 21, IntelliJ IDEA Ultimate, and Git, as well as cloning a lab repository and writing basic unit tests. Students are instructed to follow a step-by-step guide for installation and configuration, and to submit their work by the due date. Additionally, it provides guidance on using Git and writing unit tests using the Junit framework.

Uploaded by

finndog2041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views13 pages

Lab 01

The document outlines the tasks for SENG275 Lab 1, which includes installing necessary software such as Microsoft Teams, Java 21, IntelliJ IDEA Ultimate, and Git, as well as cloning a lab repository and writing basic unit tests. Students are instructed to follow a step-by-step guide for installation and configuration, and to submit their work by the due date. Additionally, it provides guidance on using Git and writing unit tests using the Junit framework.

Uploaded by

finndog2041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

SENG275 – Lab 1

Due Monday Jan 27, 12:00 pm


Welcome to SENG275. You will need to download and install several pieces of software onto our
personal computers. This week's task is to install and configure this software, and ensure that
everything's ready for the weeks to come. We’ll also get some practice writing some basic tests.
The images in this document were captured from a windows machine; there may be differences
from what you see depending on your particular technology.

Quick summary of what you need to do:

1. Install Microsoft Teams, Java 21, and IntelliJ IDEA Ultimate on your personal computer if
they are not already there.
2. Clone your lab01 repository from https://gitlab.csc.uvic.ca, and open it in IntelliJ.
3. Write some basic unit tests using the Junit platform and API.
4. Push your lab01 repository back to GitLab.

Step-by-Step:

We need to install the following software:

1. Microsoft Teams
2. Java
3. IntelliJ IDEA Ultimate
4. Git

Proceed through the list at your own pace, and please let your TA know if you are encountering
anything confusing. If you are not done by the end of the lab, please submit your screenshots
inside a zip file by next Monday at 12 pm Victoria time. If you have any questions after the lab,
send them to your TA on Microsoft Teams.
Installing Microsoft Teams

Microsoft Teams and the rest of the Office 365 suite is available for free to all UVic faculty, staff
and students. Users can only access individual teams by invitation.
Go to https://onlineacademiccommunity.uvic.ca/O365/teams/ for instructions: first you’ll have
to log in to onlineservices.uvic.ca, and sign up for Office 365. After that, you can log into
portal.office.com with your NetLink ID and passphrase and click Teams.
It may take up to 48 hours after you sign up for Teams for all the features to populate.
You can test that everything’s working fine by sending a message to the General channel, or by
sending a private message to the teaching team. To do the latter, click Chat on the left side, then
choose ‘new message in the upper-left corner, as shown:

In the To: field at the top, write TeachingTeam, and send us a message in the ‘Type a new
message’ box at the bottom of the screen. You can also attach files or images – if you run into
an error message you need help with or need to show us your code, this is a good way to do so.
Installing Java

We have tested the course software with Java 21; other versions may work as well, but if you’re
having trouble running some of the software, try installing that version.

First, check to see if you already have a Java JDK installed on your machine. Try the following two
commands at the terminal or command line: `java -version` and `java --version`. If either of them
gives you a version number, then you have java installed, and can proceed to the next section.

If both of these commands gave you an error message, then you don't have Java installed on your
machine. You need to download a Java JDK from one of the open-source implementations – I
suggest Temurin at https://adoptium.net/. Your choice of version and JVM will depend on your
platform; I recommend choosing Java 21 and the JVM 21, but any version between 11 and 21
should work fine. You may have to reboot your computer to complete the installation - repeat
the `java -version` and `java --version` terminal commands to confirm that your installation went
ok.

Installing IntelliJ

IntelliJ is a commercial development environment that is provided in two versions: the Ultimate
edition, and the Community edition. We will eventually be using some of the code coverage tools
and automated testing capabilities that are only included in the Ultimate edition, so it is best to
use that. Fortunately, every student at UVic has access to the Ultimate edition through
NetBrains' Free Educational License program.

To install IntelliJ:

1. Go to the JetBrains website at


https://www.jetbrains.com/community/education/#students
2. Click on the Apply Now button.
3. Fill out the JetBrains Products for Learning form. Where it asks to enter your email
address, make sure you provide your UVic email
address! (This will be your netlink login name, followed by @uvic.ca). Renewals
and other information from JetBrains will come to your UVic email account, so make
sure to check there for further information.

4. The confirmation email should arrive shortly - click on the link in the email to confirm
your submission.
5. You'll have to scroll down to the bottom and approve the license agreement.
6. Now you can create a JetBrains account –
Do NOT use your UVic name and password!
7. Once you've signed into the JetBrains website, you'll see a list of software that you are
able to download and install for free. We want the IntelliJ IDEA Ultimate edition – it is
available for Windows, Mac and Linux machines, so make sure you choose the
appropriate version.

8. Choose Download and save the installation file. Then Install the software. Choose
where you want to install it on your computer, and read the installation options – it is
safe to leave the boxes unchecked.

Let's make sure everything worked:

1. Run IntelliJ. You should see the Welcome to IntelliJ IDEA window open up.
2. Click New Project.
3. You'll see the New Project dialog - note that if you don't have Java installed on your
machine, IntelliJ will use its built-in Java SDK, which is currently Java 11. The version of
Java that's included with IntelliJ is limited, and JetBrains suggests we install a standalone
version, which we did above. Click Next to create a basic Java project.

4. Enable Create Project from Template, and choose Command Line App. Click Next, and
then Finish.
5. IntelliJ will show you `Main.java`, and will start downloading some things in the
background. Go ahead and add the following to the main function:
`System.out.println("Hello world.");`
6. Run the program by clicking the green play icon in the upper right corner, or by choosing
`Run -> Run 'Main'` from the menu, or by typing Shift-F10. Confirm that `Hello World.` is
printed in the output window at the bottom before continuing.

Git
You may already have Git installed on your computer. On IntelliJ, go to `File -> Settings -> Version
Control -> Git`, and click the Test button on the right. If something like 'Git is not installed'
appears, click the 'Download and install' text beside it, and install a version of git for your
machine.
Test that Git works properly : type `git --version` at the command line or in a terminal. You
should see something like `git version is 2.24.1` - the exact version isn't critical, as long as
you're reasonably up-to-date.

Your course repository is located at gitlab.csc.uvic.ca. You can find it by selecting ‘Projects ->
Your Projects’ from the upper left corner of the screen. Clone this repository to your computer,
using the HTTPS link.

This course will not be covering the use of Git, which was one of the tools covered in SENG265.
If you're having trouble remembering how to clone a repository, don't worry; some of the
commands are a little obscure. Check the hands-on tutorial provided. A more advanced
understanding of Git will be quite helpful during the labs; refer to the online book on the topic if
you wish. You will most likely need to use the ‘git config’ command to set up your git identity
(check your current configuration with ‘git config --list’), and ‘git clone’ to clone your repository.

IntelliJ has robust GUI support for most of the basic Git functions. That said, you are encouraged
to become familiar with the command line functionality provided by git. You should also feel
free to try some of the visual GUI git utilities that are out there - they may help you better
visualize changes you make to your repository. Your teaching instructors will be using the
command line exclusively, and may be unable to support you if you rely on an unfamiliar tool.

A few notes on Git best practices for this course:

- Make sure you commit frequently - at least once per exercise.


- Write clear commit messages - when writing software with others, these
messages help communicate your intent to your co-workers. If in doubt, check
out a guide on how to write clear commit messages.
- Push frequently to the GitLab remote, so that any automated builds and tests
are triggered.
Gradle

The currently available version of Gradle is 8.12, and is available from gradle.org. You can
complete everything in the course without installing gradle manually, and you will not be tested
on your knowledge of gradle at the command line, but it is a commonly-used build management
tool for Java, and familiarity with it may help you in your future career. As the course goes on,
you may decide that you like the way the software projects we test are set up (in terms of its
directory structure, etc) and want to reproduce that structure for your own projects. You can do
so using either the command-line version of gradle, or the one built-in to IntelliJ.

If you choose to investigate further, try running some of the built-in tests with gradle from the
command line. From the project's main directory, try running `gradlew check`, or `gradlew test`,
or `gradlew staticAnalysis`. Note the output, both on the console and in the reports generated
in `build/reports`. Now check the `build.gradle` file, which is where these three commands are
defined - can you see which tests were run for each?

Git repo preparation

Configure your git info if you have not done it yet. (You may prefer to configure from IntelliJ
IDEA. In that case, you may be asked for your name and e-mail address the first time you try to
commit or push, or you may add your GitLab account inside IntelliJ as well). If you are using the
command line, add your name and email.
git config --global user.name "John Doe"

git config --global user.email johndoe@uvic.ca

The, you will clone your lab01 repository – you’ll find it at https://gitlab.csc.uvic.ca/ .
You can browse your way until you find the lab01 project or you can go to the link:
https://gitlab.csc.uvic.ca/courses/2025011/SENG275_COSI/course_code/lab01
There you can find the URL for cloning on Code > Clone with HTTPS.
You can do this from the command line. Choose your project directory to start and recover the
lab01 project directory there with git clone.
git clone https://gitlab.csc.uvic.ca/courses/2025011/SENG275_COSI/course_code/lab01.git

Or you can do so from within IntelliJ (Use File -> New -> Project From Version Control). IntelliJ
has extensive Git support, so it’s usually easier to do everything from within the Git interface.
Notice that the repository you have just cloned is a read-only repo. You will first want to change
the destination of your commits to a new student repo of yours on GitLab.
To do so, first, enter your working directory (if you are using IntelliJ IDEA, you will still have to
use the command line for this change, so look for your IdeaProjects folder in your home
directory and open a terminal there). Wherever your working directory is, enter it.
cd lab01

Rename the current remote repo to old-origin.


git remote rename origin old-origin

Then, add your new lab01 student repo as the remote origin. Replace <id> with your netlinkid.
git remote add origin https://gitlab.csc.uvic.ca/courses/2025011/SENG275_COSI/assignments/<id>/lab01.git

Finally, push all the contents to your new lab01 student repo.
git push –u origin --all

Check that your push worked. On a web browser, open the following URL and then browse your
lab01 student repo on Gitlab. Replace <id> with your netlinkid.
https://gitlab.csc.uvic.ca/courses/2025011/SENG275_COSI/assignments/<id>

Now you can continue working with git the way you wish. If you are using a command-line git,
you will write add, commit and push commands. If you are using git from IntelliJ IDEA, you can
use all the available git icons, views and right button choices to perform your git commands. All
the next pushes can be done as a simple git push.

Lab 1 Exercise – write some basic unit tests

The lab01 project is a very simple one – it contains only one application class called ArrayUtils,
and that class has only one static method – isSorted(). isSorted takes an int array as input, and
returns a boolean – true if the array is sorted smallest to largest, and false otherwise. Empty
arrays or arrays of one integer are treated as sorted, as are consequtive identical values.
isSorted() is located at app>src>main>java>lab01>ArrayUtils.java. Our goal is to test this
method.

Running Tests

Our test class is located at app>src>test>java>lab01>ArrayUtilsTest.java. When we write unit


tests against a given class, we always write one test class, and we name it so that it’s easy to
remember which class it tests.
IntelliJ can run entire test suites or individual tests due its close integration with Gradle. We have
two tests that have already been written – sayHi() and sortedAAA(). Try running these tests by
clicking the arrow-and-checkmark icon in the ‘gutter’ – the column between the line numbers
and the source code.

You’ll see the results of the tests in the lower-left corner:

It is a very desirable feature of tests that they run very quickly. That said, sometimes we would
prefer to run an individual test, rather than the whole suite. Do so now for the sortedAAA()
method, by clicking on the green right-arrow-and-circle icon in the line number gutter on line 14.

Writing Tests
Let’s look at the isSortedAAA() test method.
// A sorted array
@Test
void sortedAAA() {
int[] someArray = {1,2,3,4}; // arrange
boolean someArraySorted = ArrayUtils.isSorted(someArray); // act
assertTrue(someArraySorted); // assert
}

We are using the Junit testing framework, which recognizes test methods and allows them to run
tests and see their results as shown on the previous page. To use this framework, we import
from org.junit.jupiter.api.Test. In order to mark a method as a test method, we write @Test
before the return type. The return type of any Junit test MUST be void.
Testing practitioners use the “triple-A” test structure – Arrange, Action, Assert. First we ‘arrange’
– we set up the system to permit us to run our test. This may be done in one line, as in this test,
or it may be an extensive process involving database or network access and the instantiation of
hundreds of classes. In our case, we are just creating a simple array of integers.
When we ‘act’, we call the method we’re testing. In general, we should only have one ‘action’
per test – if we interact with the code we’re testing multiple times, and the test fails, it can be
hard to tell which action caused the fault.
Finally, we ‘assert’ – we claim something, and the test passes if that thing is true. In this case, we
know that the array is sorted, so the boolean we get back from isSorted() should be true. If it is
not, we know something’s wrong with isSorted().

Assertions

Java has a built-in assert statement, but we will not be using it.
assert x == y;
is just shorthand for writing:
if (x != y) {
throw new RuntimeException();
}

Assert statements like these are DISABLED by default – they have no effect at all. They must be
enabled by passing the -ea parameter to the java command on the command line in order to
have effect. They throw unchecked AssertionError exceptions, so they do not need to be
declared with the throws statement, and should never be caught or handled in any way – their
only role is to end the program. Note the lack of parentheses; assert is a statement, not a
function (although putting in parentheses will not hurt).
This form of assert is not used to test software – it is used by the developers of software to
enforce invariants. The problem with the built-in assert statement is that it simply ends the
program unless caught, and prints difficult-to-understand information to the console. That’s not
the behavior we want – we may be running hundreds or thousands of tests, and we need simple
yes-or-no output that can be confirmed at a glance.
We will therefore not use this type of assertion in this course – this section is here to explain its
omission.

JUnit Assertions

JUnit provides an assertion class alongside its other testing framework capabilities. JUnit also
permits us to use other, third-party assertion libraries (such as AssertJ), but JUnit is pretty
straightforward, and so we’ll start with it.
To use these assertions, we’ll need to add import statements to the top of our file:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
These assertions take the following forms:
assertEquals(expected_value, actual_value);
assertTrue(some_expression);
assertFalse(some_expression);
assertSame(expected_object_reference, actual_object_reference);

There are more; see the Junit 5 documentation for the full list. People have a lot of trouble
remembering the “expected goes first, actual goes second” order, and getting them in the wrong
order can produce some very confusing error messages. IntelliJ annotates the expected and
actual arguments, so that helps, and JUnit also provides useful information in its exception
messages.
We’ll get into much more detail about JUnit and its assertions as the course goes on.

Your task:
Complete the remaining tests and confirm that they pass.

Commit and Push back to GitLab

Ensure that your tests pass, and then commit and push your changes back to your Gitlab student
remote repo. Choose Git -> Commit, and select the files in the default changelist that you’ve
altered. Type a meaningful commit message in the “Commit Message” box, and click “Commit
and Push”.
Go to GitLab and ensure that your changes are present in the remote repository.
We cannot mark your work if you do not push your changes back to gitlab.csc.uvic.ca.

Things to think about:

You don’t need to answer these questions, but it would be good to think about them as the
course goes on. Each would make a good exam question.

1. Why can’t we exhaustively test our entire software project? What should we do
instead?
2. What is the pesticide paradox about and what does it imply to software testers?
3. Why should we automate, as much as possible, the test execution?
4. Why are the test classes named the way they are?
5. How many test methods should there be in each class?
6. There are assertions, exceptions, and invariants – three related, but different
concepts. Explain in your own words the differences between these concepts, and
how they are related.
7. What is Gradle? What is it used for?

Grading Rubric

Your lab work will be graded according to the items below. You will have to send some lab work
info via Brightspace (Assignments > Lab 1) as a zip file with the information requested below.
1 mark - Microsoft Teams message sent to TeachingTeam.
1 mark - Java and IntelliJ Idea installed (send screenshot of IntelliJ Hello World run).
1 mark - Git installed and repo cloned (send screenshot of git config --list after with user
configuration and git log --oneline after the lab01 project is cloned).
2 marks - All tests added and passing, code pushed to lab 1 student repo.

You might also like