• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Testing woes

 
K Mansoor
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
K Mansoor
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mark- I'm using TestNG, I thought you didn't need @RunWith with TestNG?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark- I found the problem, wrong classpath.

Thank you for your help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic