File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Test Results 4 failed tests JUnit" Watch "Test Results 4 failed tests JUnit" New topic
Author

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

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.

 
Consider Paul's rocket mass heater.
 
subject: Test Results 4 failed tests JUnit
 
Similar Threads
InputStreamReader returns null
OOCalculator >> Sidebar >> Mike Matola
Testing void method in Junit
What causes this null pointer exception in SortedMap/TreeMap?
JUnit testing with int[] result