Skip to content

Write a unit test

Goal

Add a new Burger Option for Bacon Cheeseburger, which will cost $8.

Clone Meal Kiosk repository

From your Git command line, clone the repository:

C:\training> git clone https://github.com/spiral-learning/mealkiosk-starter

Import into IntelliJ

  1. Open the pom.xml file by doing the following:

    • If you see the Welcome screen, choose Open (not Import)

    Otherwise...

    • From the File menu, choose the Open... item and find the pom.xml (don't use Import) in the project directory that you cloned above.
  2. IDEA will then ask you how to open this file. Since we want it to be a new project, click Open as Project.

  3. The project will load and IDEA will do some indexing, which may take a few minutes.

Run all tests

Once the project is loaded, find the test directory in the Project Window, right-click on the package name (com.welltestedlearning.mealkiosk) and select Run Tests in...

If any tests fail, have the instructor help you.

Write new test

You're going to add a new Burger Option for Bacon Cheeseburger, which will cost $8.

  1. Write a new unit test in the BurgerTest class

    a. Create a new method with the @Test annotation

    b. ?? What will you name the test ??

    c. Write the assertion first, where you want the burger.price() to be 8.

    d. Add a new option to the BurgerOption enum and call it BACONCHEESEBURGER

    e. Use the new option to instantiate a new Burger instance

    f. Run the test -- it should fail

  2. Write the code in Burger that will make the test pass


Once you've completed the above steps, check in with the instructor to review your code.