File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Spring Testing woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Testing woes" Watch "Spring Testing woes" New topic
Author

Spring Testing woes

K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
It appears as though classes are not being scanned for annotations. What am I missing?

I am getting the following error while trying to run a TestNG+Spring test:



My Test:


The Dao:


test-focus-servlet.xml:


build.xml (relevant sections)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

You are missing the @RunWith annotation on your test class to tell JUnit to use Spring's TestRunner instead of the build in one with JUnit.

@RunWith(SpringJUnit4ClassRunner.class)

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
Hello Mark- I'm using TestNG, I thought you didn't need @RunWith with TestNG?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Sorry, didn't notice the extends part and just assumed JUnit.

In the Spring Javadocs I saw this about classes that extend AbstractTransactionalTestNGSpringContextTests

"Must have constructors which either implicitly or explicitly delegate to super();."

I don't see a constructor and not sure if the default no-args constructor will call super() for you. Try to put in a no args constructor that calls super() and see if that works.

Also, does your test-focus-servlet.xml define beans for dataSource and transactionManager as those are required too.

Note, I am going by the docs as I have always just used JUnit

Mark
K Mansoor
Ranch Hand

Joined: Jan 10, 2006
Posts: 52
Hi Mark- I found the problem, wrong classpath.

Thank you for your help.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

K Mansoor wrote:Hi Mark- I found the problem, wrong classpath.

Thank you for your help.


Um, no problem, although I was of no help in this case.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Testing woes