Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How To Test Negative Paths in the Spring Framework?

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am going to test all the exceptions that can be thrown - provide some error input, if the exception thrown is what I expect, the JUnit test passes. And the project uses the Spring framework. I am not familiar with testing in the Spring framework; henceforth, I am writing to seek help.

Is it true that all I have to do is to write for the "numberFormatAsserter" class? How do I code it? Thank you.



THE_SPRING_CONFIGURATION_FILE.xml
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring has got an entire chapter dedicated to Testing in its documentation and its pretty easy to follow if you already know JUnit.

Also I don't follow you questions. Looks like you already have your test class ready - so exactly what are you looking for?
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where do I find the chapter that is dedicated to Testing?

I am supposed to write unit tests for all kinds of data errors that developers can think of. If the error is what expected, it should pass the unit test. I simply would like to start with an example; say, the NumberFormatException. My question is how do I code it?

Thank you.
 
author & internet detective
Posts: 40847
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The testing chapter in the docs. Your test looks fine. Are you encountering a problem?
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that I was not specific enough. In the Spring framework shown in the earlier posts, how do I let the "null" output to pass the JUnit test? For example, I did something below. But, the JUnit test gives me the java.lang.AssertionError: Expected exception: java.lang.NullPointerException. But the NullPointerException is what I expected. I want to let it pass. In the Java class that is being tested, I have:

In the Spring configuration file:


 
reply
    Bookmark Topic Watch Topic
  • New Topic