Reputation: 11524
I have created an extremely simple junit test, which creates a null product in the product table in the db.
@Test(expected = IllegalArgumentException.class)
public void testCreate_NULL() {
Product p = null;
createProduct(p);
}
but when I do the junit test it turns blue.
btw. other tests like creating a product, deleting ect. are all green...
I appreciate your answer!!!
PS.: I am using hsql db!
PPS.: The error is:
java.lang.AssertionError: Expected exception: java.lang.IllegalArgumentException at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:35) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
UPDATE:
my createProduct Method justs inserts a product into the db and before it checks:
if(p==null) {
throw new IllegalArgumentException("null objects impossible");
}
Upvotes: 1
Views: 2600
Reputation: 1500065
Perhaps it's throwing NullReferenceException
instead of IllegalArgumentException
? You should be able to see in the test failure details.
It's fairly hard to diagnose this without any indication of what's in the createProduct
method.
Upvotes: 3