CS 212 Software Development

CS 212-02 • Spring 2020

Homework Testing

Every homework comes with a test directory with JUnit 5 test code. You must pass all of these tests using the homework script on the lab computers as part of the homework requirements.

Local Testing

You should try passing the tests locally before you try passing them remotely. Before you can do that, you need to follow the homework setup guide to setup the your repository using Github classroom and then import that repository as a Java Project in Eclipse.

To run the JUnit tests provided with the homework template, follow these steps:

  1. Open up the test subfolder in the Eclipse project.

  2. Open up the class containing the same name as the homework assignment plus the suffix Test at the end. For example, for the TextFileStemmer homework assignment, TextFileStemmerTest is the associated test class.

  3. From the “Run” menu, select “Run As” » “JUnit Test” from the menu. If prompted which tests to run, select the one with the same name as the class. For example, for the TextFileStemmer homework assignment, TextFileStemmerTest is the associated test class. This will be the set of tests run by the homework script on the lab computers.

    Note: You can run just the nested tests or one test at a time if you want. This can help you focus on a small number of tests at a time as you develop the code. To do this, right-click the test method or nested test class, and select “Run As” » “JUnit Test” from the popup menu.

  4. Running the tests should open the “JUnit” view. You can use that view to see which tests you are passing and which you are not. See the Eclipse User Guide for what each of the buttons mean in this view.

  5. After making changes to your code, you can re-run the tests by following the same steps or clicking the Rerun Test Rerun Test button.

It is important you only try to pass one test at a time, because the changes you make may affect other tests. You should git commit your changes every time you start passing a new test at a minimum, and git push your changes at the end of every coding session.

Remote Testing

Once you are passing all of the tests locally, it is time to test your homework remotely. There are two primary steps to this process: committing and pushing your changes to Github, and then logging into a CS Lab computer and running the homework script.

After you have updated your remote Github repository, login to a CS lab computer and run the following command from a terminal:

Replace GitUser with your GitHub username and HomeworkName with the name of the homework you want to test. For example:

This script will clone your remote Github repository, fetch fresh test code (in case you changed anything) from the template repository, compile the Java code, and then run all of the JUnit tests and report how many tests passed or failed. This script is used for grading homework.

If you want the detailed output of running the tests, you can add the -debug flag to the command. This will leave the downloaded and compiled homework files in a directory named ~/cs212-HomeworkName-???? where ~/ is your home directory and ???? is a randomly generated string. If you are familiar working on the terminal, you can then look at the output generated by the script, rerun the tests via the terminal, or modify and recompile the source code.

 Careful! Every time you run the homework script with the -debug flag, it creates a new copy of your code. If you do not remember to remove those directories manually up after you are done debugging, you can eventually use up your entire space quota on the lab computers!

Bonus: Aliases

You will be doing this quite a bit, so I recommend making an alias. To do this, open the ~/.bashrc file on a lab computer and add the following line:

Replace GitUser with your GitHub username. Run source ~/.bashrc for the command to take affect.

If you are uncomfortable with editing a file via the command line, you can run this command on a lab computer to do it for you:

Then, you can test homework using the following command on the lab computers:

Replace HomeworkName with the name of the homework you want to test. The alias will still work with the -debug flag as well!

You only need to set the alias once. Every time you login again, the .bashrc file will re-add that alias for you.

Video Walkthrough

 Homework submission has changed since this video was recorded. However, the other steps remain the same.

This video walkthrough will illustrate this entire process on a Mac OSX system.


https://youtu.be/QSC1gK6TtSk