Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

What am I doing wrong with the @before?

I am currently doing the Unit Testing in Java Track in the Using Before to not repeat yourself challenge and i have no idea what i am doing wrong here.

Here is the Code: package com.example;

import org.junit.Before; import org.junit.Test;

import static org.junit.Assert.*;

public class CalculatorTest {
private Calculator calculator;
    @Before
    public void setUp() throws Exception {
        Calculator calculator = new calculator();
    }

    @Test
    public void addingMultipleNumbersProducesResult() throws Exception {
        int answer = calculator.addNumbers(1 ,2, 3);

        assertEquals(6, answer);
    }

    @Test
    public void addingSingleNumberTotalsAppropriately() throws Exception {
        int answer = calculator.addNumbers(1);

        assertEquals(1, answer);
    }
}

and when I push check work I get: ./com/example/CalculatorTest.java:12: error: cannot find symbol Calculator calculator = new calculator(); ^ symbol: class calculator location: class CalculatorTest 1 error

Can someone please help me here?

(edited for markdown. Rbridges)

1 Answer

Hey Oliver, it might just be something as silly as not capitalizing Calculator when creating the new object, you have

Calculator calculator = new calculator();

Try

Calculator calculator = new Calculator();

I hope this helps.

PS, edited your code for mark downs, hope it's more readable now.

thank you i got it working :D