0

i'm having a trouble with Junit where when I run my test case after changing something in the code, junit does not read through the updated code but instead reads from the original code. For eg: if I change a parameter from "xxx" to "yyy", Junit is going to run with "xxx" as parameter even after i save it with "yyy".

One solution I found to it was to go to the pom.xml file and remove all the dependencies, do the maven update, let the error show up and then put back the dependencies back in and then by saving it. I'm not sure why is this happening, if its Junit or Maven I'm having trouble with.

Anyone know anything about this????

Neil
  • 1
  • 1
  • 2
  • 2
    Did you rebuild after saving the changes? – Christian Frommeyer Nov 19 '14 at 21:13
  • Yeah after I build it, I get an error saying class not found, which is the class I'm actually testing. – Neil Nov 19 '14 at 21:37
  • Are you using an IDE like eclipse to run your Junit tests or are you running the tests from command line using maven? – mystarrocks Nov 20 '14 at 00:04
  • I am using Eclipse for now, haven't tried it using maven though.. – Neil Nov 20 '14 at 15:10
  • Can you tell us a little more on your project layout (and how you integrated to eclipse)? As this usually works out of the box it sounds like you changed s.th. diverting from the defaults. – Christian Frommeyer Nov 21 '14 at 10:24
  • So the project is a test case that has two other external dependencies in it. The classes are Junit test classes. I imported the project using existing maven project and thats it. My tests are in src/main/java, i'm using Junit4. Hope it helps!!! – Neil Nov 21 '14 at 15:13

2 Answers2

3

Assuming that you are using Eclipse, try this:

1 - Right click the src/test/java folder in the Package Explorer

2 - Select Build Path -> Configure Output Folder

3 - Enter target/test-classes, click OK

If no luck, check this answer: Eclipse/Maven: JUnit tests not compiled when running them

Community
  • 1
  • 1
Luke SpringWalker
  • 1,600
  • 3
  • 19
  • 33
  • I tried using it but no luck again. It somehow is not reading through the updated class and I dont even know what to search on google for that... lol – Neil Nov 20 '14 at 15:09
  • Check the link I added. – Luke SpringWalker Nov 20 '14 at 15:12
  • I tried using the solutions provided on the link, still it doesnt work. I'm not sure what could be the problem. Maybe I need to reinstall Maven and see if that works or not. – Neil Nov 20 '14 at 18:09
0

Finally after a very long process of finding the error I was able to make it work. The problem that I had was that I had cyclic maven dependency in the pom file and also I had build path as a dependency too besides the maven depeendency. I had to remove the eclipse dependency and update the cyclic dependency along with correct artifact id name and it worked.

Neil
  • 1
  • 1
  • 2