CSCI-1320 Lab: Unit Tests for MathOperations Class

Instructor: Todd Dole

Purpose Statement

In this lab, we will practice creating unit tests with JUnit, using our MathOperations class from the previous week's lab. Then, we will add a new method using test driven development principles.

Instructions

Part 1: Set up JUnit

Follow the instructions here to install and configure JUnit 4.

Part 2: Create Unit Tests for MathOperations

Part 3: Test Driven Development

Now, let's practice test driven development. Remember that the idea is to create a unit test for a new method first (Red), and then write the code so that the test passes (Green).

Paste the following code into your MathOperationsTest.java file:

                @Test
                public void testCelciusToFahrenheit() {
                    assertEquals(MathOperations.celciusToFahrenheit(0), 32);
                    assertEquals(MathOperations.celciusToFahrenheit(100), 212);
                }

            

Now, write a celciusToFahrenheit method that will make the test pass! (Hint: the formula is the reverse of the Fahrenheit to Celcius formula we used last week.)

Part 3: Submission

Submit both MathOperations.java and MathOperationsTest.java via Canvas by the due date. Make sure you are submitting this week's versions from your Project src folder!