system-rules icon indicating copy to clipboard operation
system-rules copied to clipboard

TestNG support

Open cezarykluczynski opened this issue 8 years ago • 11 comments

Hi.

Is there any chance for TestNG support?

cezarykluczynski avatar Feb 12 '16 20:02 cezarykluczynski

I have plans for a Java 8 version of this library that does not need JUnit rules. Which version of Java do you use?

stefanbirkner avatar Feb 12 '16 21:02 stefanbirkner

@stefanbirkner It would be cool if this library could be framework-agnostic. I use Java 8.

cezarykluczynski avatar Feb 12 '16 21:02 cezarykluczynski

It will. Unfortunately it will not be as easy to use as the rules and TestNG is does not have any extension points like rules. (http://stackoverflow.com/questions/6099633/does-testng-support-something-like-junit4s-rule)

stefanbirkner avatar Feb 12 '16 21:02 stefanbirkner

Which rule are you looking for foremost?

stefanbirkner avatar Feb 12 '16 21:02 stefanbirkner

@stefanbirkner As for now, I'm using ExpectedSystemExit. I haven't found any other way to test code that calls System.exit().

cezarykluczynski avatar Feb 12 '16 22:02 cezarykluczynski

I keep you updated on the progress of the new library. Hopefully I can provide a first release for testing System.exti() in the next few days.

stefanbirkner avatar Feb 12 '16 22:02 stefanbirkner

@stefanbirkner Thanks!

cezarykluczynski avatar Feb 12 '16 22:02 cezarykluczynski

Would this work for you:

@Test
public void test() {
  int statusCode = catchSystemExit(() -> {
    //here comes your code that calls System.exit(...)
  });
  assertEquals(0, statusCode);
}

stefanbirkner avatar Feb 14 '16 15:02 stefanbirkner

@stefanbirkner Sure, looks right.

cezarykluczynski avatar Feb 14 '16 19:02 cezarykluczynski

I started to create a library called System Lambda that solves the same testing problems like System Rules but without a dependency to a test framework. If that solves your problem, I will not provide a specific TestNG extension.

stefanbirkner avatar Apr 26 '18 07:04 stefanbirkner

It will. Unfortunately it will not be as easy to use as the rules and TestNG is does not have any extension points like rules. (http://stackoverflow.com/questions/6099633/does-testng-support-something-like-junit4s-rule)

Are TestNG listeners suitable? http://testng.org/doc/documentation-main.html#testng-listeners

pavetok avatar Dec 13 '18 10:12 pavetok