#"cannot find symbol - variable echoClient" but the symbol exists

1 messages · Page 1 of 1 (latest)

fresh ruin
#

I'm trying to make a test class for a simple client/server, but for some reason it's telling me the symbol does not exist, when it does. I'm using @Before to set up the connection, and then @After to tear it down, but in the @Test it's telling me it can't find the symbol.

    @Before
    public void setUp() { //this works fine
        EchoClient echoClient = new EchoClient();
        echoClient.startConnection("127.0.0.1", 4444);
    }

    @Test
    public void givenClient_whenServerEchosMessage_thenCorrect() { // for some reason it can't see echoClient
        String resp1 = echoClient.sendMessage("hello");            // even though it's set up in setUp()
        String resp2 = echoClient.sendMessage("world");
        String resp3 = echoClient.sendMessage("!");
        String resp4 = echoClient.sendMessage(".");
    
         assertEquals("hello", resp1);
         assertEquals("world", resp2);
         assertEquals("!", resp3);
         assertEquals("good bye", resp4);
    }

    @After
    public void tearDown()
    {
        echoClient.stopConnection(); // same issue as in the test method
    }

Ignore my horrendous method name

mellow caveBOT
# fresh ruin I'm trying to make a test class for a simple client/server, but for some reason ...

Detected code, here are some useful tools:

Formatted code
@Before
public void setUp() {
  //this works fine
  EchoClient echoClient = new EchoClient();
  echoClient.startConnection("127.0.0.1", 4444);
}
@Test
public void givenClient_whenServerEchosMessage_thenCorrect() {
  // for some reason it can't see echoClient
  String resp1 = echoClient.sendMessage("hello");
  // even though it's set up in setUp()
  String resp2 = echoClient.sendMessage("world");
  String resp3 = echoClient.sendMessage("!");
  String resp4 = echoClient.sendMessage(".");
  assertEquals("hello", resp1);
  assertEquals("world", resp2);
  assertEquals("!", resp3);
  assertEquals("good bye", resp4);
}
@After
public void tearDown() {
  echoClient.stopConnection();
  // same issue as in the test method
}
#

<@&987246399047479336> please have a look, thanks.

mellow caveBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

junior lily
#

did u make a field above the setup ?

#

EchoClient echoClient;
@Before
    public void setUp() { //this works fine
     echoClient = new EchoClient();
fresh ruin
junior lily
#

u need a field, else it only lives in the setup method

fresh ruin
#

I assumed it wasn't necessary since @Before runs before every single method

junior lily
#

yep , to 'reset' things basicly

#

same with the after / afterAll

fresh ruin
#

ah, sick thanks! I knew it was gonna be something stupid haha