stefanbirkner / system-rules

A collection of JUnit rules for testing code which uses java.lang.System.
http://stefanbirkner.github.io/system-rules
Other
546 stars 71 forks source link

TestNG support #41

Open cezarykluczynski opened 8 years ago

cezarykluczynski commented 8 years ago

Hi.

Is there any chance for TestNG support?

stefanbirkner commented 8 years ago

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

cezarykluczynski commented 8 years ago

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

stefanbirkner commented 8 years ago

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 commented 8 years ago

Which rule are you looking for foremost?

cezarykluczynski commented 8 years ago

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

stefanbirkner commented 8 years ago

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.

cezarykluczynski commented 8 years ago

@stefanbirkner Thanks!

stefanbirkner commented 8 years ago

Would this work for you:

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

@stefanbirkner Sure, looks right.

stefanbirkner commented 6 years ago

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.

pavetok commented 5 years ago

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