The purpose of this initial assignment is to familiarize yourself with the process of running the autograding tests and submitting your work via GitHub Classroom. Even if you are familiar with GitHub Classroom, this assignment will contain several new items that are specific to working with Java assignments.
Let’s set up the assignment on our computer and learn about its basic structure.
First, find Assignment #0 in Canvas and click on the invitation link. After accepting, go to your assignment repository on GitHub.
Make sure IntelliJ is running and all project windows are closed. You should see IntelliJ’s Welcome pane. From here, select the Get from Version Control option.
While IntelliJ is working, go to your assignment repository on GitHub and copy the clone URL.
Paste this URL in the URL field of the Get from Version Control pane that IntelliJ has opened. Make sure the Directory field is the location that you want your assignment to be saved within, then click the Clone button.
After IntelliJ clones your repository, it will prompt you to open it. Select Yes.
When the project opens initially, the Project pane, which shows the files within your project, may be closed. If so, click on the pane’s button at the top left to open it.
Navigate though the directories down to the HelloWorld
class. This will be in the src/main/java/
directory. For all of the assignments we work on in this unit, our source code will live within this directory.
Note that there are two green “play” buttons on the left of the source code. This indicates that IntelliJ recognizes this class as being runnable. You can use either of these buttons to run the program. They function exactly the same. Clicking on one of them opens up a menu with a few options. Choose the first to run the program.
When the program runs, IntelliJ will open a pane at the bottom of the window and display program output. Currently, the program has no output. You’ll fix that in a bit.
Up to now, you have have had to push your code to GitHub in order to see grading results. For this unit, you’ll be able to run the autograding tests yourself before you push your code. This will make it quicker and easier to know whether or not your code is correct. Let’s learn how to run the tests.
In the Project pane, navigate to the test class, TestHelloWorld
, in the directory src/test/java
. For each assignment, this directory will contain all of the autograding tests, and it may have more than one class.
Notice the two slightly different “play” buttons at the left. The topmost button is actually two green “play” arrows staked on top of each other. It allows you to run all of the tests in a given file.
The lower button, next to the testSayHello
method, will run only that individual test. A test is a single method in a test file that has @Test
just above it. A test file may have multiple tests.
Run all of the tests (in this case, there is only one) but clicking on the topmost button.
A menu opens, and selecting the first option runs the tests.
When IntelliJ runs the tests, it opens a pane at the bottom of the window to display test results. At the left, we see that the test has failed. We can expand the tree to see each of the individual tests (again, in this case there is only one). Selecting one of the tests shows its results to the right.
This console-based test output can be hard to read, but IntelliJ provides a nicer interface for viewing test results. Follow the Click to see difference link to open this pane.
On the left, you’ll see the output that the test expected. On the right, you’ll see the output that your program actually provided. IntelliJ will highlight the difference between the two, showing you exactly why your test failed.
In this case, the test expected our code to output Hello, World!
. Instead, it provided no output at all.
Warning
The autograding tests are VERY exacting. A difference of just one character will result in a failed test. The tests are also case-sensitive. You’ll need to pay attention to detail in order complete your assignments.
When your code is correct, IntelliJ will display a green checkmark indicating passing tests.
Your task is simple: make the program print out the string "Hello, World!"
. Edit the code in the HelloWorld
class, withing the sayHello
method. When your code is correct, running the tests will display passing results.
Once you get all of the tests to pass, open IntelliJ’s Terminal pane. Then you should commit and push your code to GitHub.
Visit your assignment repository page. Near the top right, you’ll see a green checkmark indicating that GitHub has graded your assignment as passing. If you see a red X, then your assignment is not yet correct.
This process will be the same for all of your assignments in this unit. Revisit this page as needed to review instructions on running tests in Java projects.