wood burning stoves
The moose likes Testing and the fly likes Test Results 4 failed tests JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Test Results 4 failed tests JUnit" Watch "Test Results 4 failed tests JUnit" New topic

Test Results 4 failed tests JUnit

Tom Mordon
Ranch Hand

Joined: Apr 26, 2012
Posts: 30
I have been stuck on these test failures and have narrowed it down to the Order.calHandlingCharge() method. When I run and compile the program it works but I have these last 4 of 21 tests that fail in JUnit. Any thoughts? The error given is "caused an ERROR: java.lang.NullPointerException"

Any thoughts on what I can do to get it to pass the tests? I think that its not creating and instance of something that it needs for testing?

Pasted below: OrderTest.java, Order.java, ProcessOrder.java, OrderDriver.java

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

Yes. hChargeQuantity is null. I found this out by running the code and looking at the stack trace of the failure. Try tracking the code that calls setHChargeQuantity() to see why this is the case.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Where in your code do the fields defined on lines 289 and 290 get assigned valid references to arrays? By default, these will be set to null when an object is instantiated.

Junilu - [How to Ask Questions] [How to Answer Questions]
Tom Mordon
Ranch Hand

Joined: Apr 26, 2012
Posts: 30
Good point they do not get created/instantiated or assigned a value by anything. I thought this was ok because I'm only comparing them to another null value, but maybe they are not a null value. I will assign them a value and compare to that value.

I agree. Here's the link: http://aspose.com/file-tools
subject: Test Results 4 failed tests JUnit
It's not a secret anymore!