srikotesh
asked on
how to write JUnit test cases for spring application using annotations
hi,
i have to write JUnit testcases for spring appln through annotations,can any one suggest advice,useful links to me.
i have to write JUnit testcases for spring appln through annotations,can any one suggest advice,useful links to me.
ASKER
I've requested that this question be deleted for the following reason:
i know those steps
i know those steps
You need to provide a proper explanation for deleting the question. What you have done is not sufficient. If you don't do that then the delete request will be stopped and you will need to close the question in a different way.
I'm objecting to the deletion of this question, as I believe my comment (http:Q_28299158.html#a39664483) sufficiently answers the (very briefly worded) question. Also, the question author has made no attempt to follow up on my comment or ask additional questions. And finally, the (also very briefly worded) explanation for deletion is inadequate. Attempts to resolve this with the question author have been ignored.
ASKER
sorry for that attempt actually i postponed my practice. i need to test spring application using junit testcasese.
i created one testcase and i imported those two steps
@RunWith(SpringJUnit4Class Runner.cla ss)
@ContextConfiguration(loca tions = {"classpath:data-servlet.x ml"})
after that i called one method i inserted hard code values finally i called service mehod
while running the junit test i am getting error.
Failed to load ApplicationContext
parsing XML document from class path resource [data-servlet.xml]; nested exception is java.io.FileNotFoundExcept ion: class path resource [data-servlet.xml] cannot be opened because it does not exist
class path resource [data-servlet.xml] cannot be opened because it does not exist
any problem if i import the statement like this @ContextConfiguration(loca tions = {"classpath:data-servlet.x ml"})
can u give a proper suggestion for me.
i created one testcase and i imported those two steps
@RunWith(SpringJUnit4Class
@ContextConfiguration(loca
after that i called one method i inserted hard code values finally i called service mehod
while running the junit test i am getting error.
Failed to load ApplicationContext
parsing XML document from class path resource [data-servlet.xml]; nested exception is java.io.FileNotFoundExcept
class path resource [data-servlet.xml] cannot be opened because it does not exist
any problem if i import the statement like this @ContextConfiguration(loca
can u give a proper suggestion for me.
any problem if i import the statement like thisNo, it appears that you are correctly using the ContextConfiguration annotation. The problem might be exactly where Spring is looking for the file.
Can you tell me the exact directory that your "data-servlet.xml" is located in? Also can you tell me the package name that this TestCase class has?
ASKER
directory location for data-servlet.xml is:
WebContent/WEB-INF/data-se rvlet.xml
pkg name for Test class:
com.hcltech.poc.ets.test.M anagerPage Controller Test
pkg name for Service class:
com.hcltech.poc.ets.servic e.TaskServ iceProvide r
WebContent/WEB-INF/data-se
pkg name for Test class:
com.hcltech.poc.ets.test.M
pkg name for Service class:
com.hcltech.poc.ets.servic
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your suggestions i have a habit like if i didn't get the solution for my question i will delete my question from the portal i think mccrl you saw only my answered questions previously i deleted many questions because of i didn't get exact input from experts.
I dont know A is the default rating just now i saw the ratings.
I dont know A is the default rating just now i saw the ratings.
ASKER
i got the proper input from you.Thanks for your suggestion.
@srikotesh,
Thanks for accepting, and explaining why your reasons for grading the way your did.
And to follow from what SouthMod posted, I didn't bring this up just for my own benefit, or to enforce the policy for sake of enforcing it, but to help you to hopefully get a high level of help from the other experts here. :)
Cheers
mccarl
Thanks for accepting, and explaining why your reasons for grading the way your did.
And to follow from what SouthMod posted, I didn't bring this up just for my own benefit, or to enforce the policy for sake of enforcing it, but to help you to hopefully get a high level of help from the other experts here. :)
Cheers
mccarl
http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/testing.html
...but probably start reading from section "10.3.5 Spring TestContext Framework".
In a nutshell though, the annotations that will be of the biggest use to you are...
Open in new window
Once you have this setup, you can use normal Spring @Autowired annotations to inject references from your Spring configuration into your test class, and then use the normal JUnit annotations to run your tests.If you can provide more information about your unique situation/requirements we can probably help a little more too.