IntelliJ Java IDE
The moose likes Spring and the fly likes How To Test Negative Paths in the Spring Framework? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "How To Test Negative Paths in the Spring Framework?" Watch "How To Test Negative Paths in the Spring Framework?" New topic
Author

How To Test Negative Paths in the Spring Framework?

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 314
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
Sam Mercs
Ranch Hand

Joined: Feb 08, 2009
Posts: 539

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?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 314
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 23635

The testing chapter in the docs. Your test looks fine. Are you encountering a problem?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 314
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:


 
 
subject: How To Test Negative Paths in the Spring Framework?
 
Threads others viewed
AOP not getting invoked on my Target Bean Method --> Singer.perform() method
Why cannot ApplicationContext find an existing file?
HibernateException: No Hibernate Session bound to thread
Advice PointCut methods not being called?
Hibernate with Spring
IntelliJ Java IDE