I am running automation tests using TestNG and Java.
Here is part of my code:
private void testConnection(String URL1) throws IOException {
try {
URL url = new URL(URL1);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
assertEquals(HttpURLConnection.HTTP_OK, urlConn.getResponseCode());
} catch (IOException e) {
ConsoleLogger.error("*******************************");
ConsoleLogger.error("Could NOT connect to the server");
ConsoleLogger.error("Entire test is aborted!!!");
ConsoleLogger.error("Please check port and IP again!");
ConsoleLogger.error("*******************************");
throw e;
}
}
Now, my test fails because I am getting an exception from the URL. I can see in the console the error message/s. This method is being called in a method with the annotation @BeforeSuite.
Why can’t I debug this method (not the try block nor the catch block)?
You've mentioned that your breakpoints are not being respected by IntelliJ and I can see from your code that there are references to a server. This might be happening if you are trying to do remote debugging:
To debug your code on a server you have to attach your debugger to its debug port. This means starting the server in debug mode, and creating a Remote debugging run configuration in IntelliJ attached to the correct port (which should be reported in your server initialisation logging).
For more information read the the original answer here.
If you are not remote debugging you can try do to the following:
I was assuming you are working in IntelliJ for some reason but all of these points should work for other programs as well.
Since you can print out the error message, definitely you have chance to debug. You can try to set break point at that printing error message. If it still fail. Means your workspace is not update with your code. Just refresh or restart your IDE. Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With