Errors in simple fault injection with TestNG and maven
andou528 Apr 22, 2016 4:38 PMHi All :
I am trying to modify the TestNG test case in the tutorial "BMUnit : Using Byteman with JUnit or TestNG from maven and ant".
But there some errors I cannot figure it out.
The modified method openFile():
public PrintStream openFile() { File file = new File(filename); try { FileOutputStream fos = new FileOutputStream(file); PrintStream ps = new PrintStream(fos, true); testVariable = false; return ps; } catch (FileNotFoundException e) { System.out.println("Unable to open file " + file.getName()); System.out.println(e); testVariable = true; return null; } }
The modified test case:
@Test @BMRule(name = "test exception catch", targetClass = "org.my.app.WebWriter", targetMethod = "openFile()", targetLocation = "AFTER WRITE $testVariable", action = "throw new java.io.FileNotFoundException( \"Ha ha Byteman fooled you again!\" )" ) public void testExceptionCatch() { System.out.println("-------- testExceptionCatch start ---------"); WebWriter writer = new WebWriter("foo.html", "Andrew"); PrintStream ps = writer.openFile(); Assert.assertTrue(ps == null); System.out.println("-------- testExceptionCatch end ---------\n"); }
What I want is changing the place to inject the fault.
But I get the following errors:
------------------------------------------------------- T E S T S ------------------------------------------------------- Running TestSuite byteman jar is /Users/AAA/.m2/repository/org/jboss/byteman/byteman/2.2.1/byteman-2.2.1.jar objc[92708]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Setting org.jboss.byteman.allow.config.update=true Setting org.jboss.byteman.debug=true Setting org.jboss.byteman.verbose=true TransformListener() : accepting requests on localhost:9091 TransformListener() : handling connection on port 9091 -------- testExceptionCatch start --------- org.jboss.byteman.agent.Transformer : possible trigger for rule test exception catch in class org.my.app.WebWriter org.jboss.byteman.agent.Transformer : inserted trigger for test exception catch in class org.my.app.WebWriter TransformListener() : handling connection on port 9091 retransforming org.my.app.WebWriter TransformListener() : handling connection on port 9091 Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.95 sec <<< FAILURE! Results : Failed tests: testExceptionCatch(org.my.WebWriterTest3) Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
I found this post "Can't inject RuntimeException: ensureTypeCheckedCompiled fails" might be useful. But it says the bug is closed.
https://issues.jboss.org/browse/BYTEMAN-173
Can anyone give me some hints? Thank you.