0
votes

I'm having trouble debugging test classes when using TestNG Factories. It seems like, when in Debug mode, you can only debug as far as the factory class.

In the following example, it's possible to debug in WebTestFactory and impossible in WebTest.

Factory class:

public class WebTestFactory {
  @Factory
  public Object[] createInstances() {
   Object[] result = new Object[10]; 
   for (int i = 0; i < 10; i++) {
      result[i] = new WebTest(i * 10);
    return result;
  }
}

Test class:

public class WebTest {

  // **** BREAKPOINTS IMPOSSIBLE HERE ****

  private int m_numberOfTimes;
  public WebTest(int numberOfTimes) {
    m_numberOfTimes = numberOfTimes;
  }

  @Test
  public void testServer() {
   for (int i = 0; i < m_numberOfTimes; i++) {

    }
  }
}

EDIT: Additional info: My current project structure is that the test class and the factory are in different projects. The Factory is in the project from which I run my tests, and the test class is in an external jar.

EDIT: It's not a TestNG problem. Just Eclipse going crazy again!

1

1 Answers

2
votes

I really doubt TestNG has anything to do with your problem: Java code is Java code, if Eclipse can run it, Eclipse can debug it. The fact that the code is in a different jar or a different project makes no difference. What might make a difference is if tests are running in a different process, but I doubt it's the case here.

There are a number of reasons why Eclipse wouldn't let you put a break point somewhere, I suggest you Google the topic and report back here.