This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In order to run junit 4.8.2 in maven do we need to have the folder src/test/java?

 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to run junit in java but keep getting the following error when i execute mvn clean install:



Please find below how junit is declared in my pom.xml:


However i don't have the folder src/test/java, is it why i keep getting build failure when i run mvn clean install?

Can anybody help me please how to resolve this issue?

Thanks a lot in advance.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junit dependency declared is correct. Pl check local repo (.m2) for junit 4.8.2 jar, it might be the case that junit is not on classpath.
 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have checked it ,i have the jar file in the following directory:


However when i change the scope from test to compile in my pom.xml there is no build failure but it seems that it just skip the test when its executing the mvn clean install.

Any suggestion please?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have your tests in a "non-standard" location, you do need to tell JUnit where they are. This is actually move of a Maven question than a JUnit one so moving to our Builds forum. This testing forum will link to the new location making it easy to find.
 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

How do i tell JUNIT where my directory is?

I am using Maven.

Thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ashley Jug wrote:However i don't have the folder src/test/java,

Try creating "src/test/java" dir and move your junit classes in it.
 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I created the dir 'src/test/java' earlier in eclipse for my project but maven is just ignoring the test.

Still trying to find out a solution though

Thanks
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create src/test/java, did you move your unit tests to that directory?

It would also help if you post the error that you are now getting. If it is still the same as the original error, then you have not moved all of the unit tests out of src/java/main. Your dependency on junit has a scope of test which means that junit will not be included in the classpath when src/main/java is compiled; instead is is included only when src/text/main ois compiled and when the unit tests are run.
 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have moved the test class in the directory src/test/java.My junit test in pom.xml is defined as follows:




I had also changed the plugin in my pom.xml:


The skipTest tag was true before i have changed it to false, this was why it was skipping the test. However when the junit test should fail and when i run mvn clean install comand it gives me a build success message. According to the log it seems that there is no junit class to test.



If it can help out this is my junit class:




Any suggestion please?

Thanks in advance.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running mvn with the -X option and see if that gives a clue as to what is going on. If you can't tell anything from that, run it again with -X and redirect both stderr and stdout to a file and attach that file.

Also, post the full file and directory tree for your project (you can ignore the target directory). Base on your directory names I suspect you are running Windows, so to get the directory tree run this from the project's basedir:



And attach the pom.xml file.

Either you are doing something incorrectly or there is something very strange going on. But I will need access to the entire project to be able to tell.

If you cannot do this because of the proprietary nature of your code, create a simple sample project that exhibits the same behavior and post the information about that project.
 
ashley Jug
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks a lot for you advice Peter. Now its resolved basically it was ignoring my test class because of the naming convention. It was Junit_TestSQL.java instead my class should start with the word Test, for instance TestJunitsql.java. When my test class start with the word Test it recognizes it as a JUNIT class test. I don't know why it does that but it did resolved my problem.

Thanks again.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds as if JUnit 3.x was used to run the unit tests; if I recall correctly it required the test classes to start with the word Test (or was it that the methods had to start with the word "test"?). None of my unit tests start with Test.

Or perhaps is has something to do with the version of the surefire plugin that you are using. What version of Maven are you running? Or it could be the JVM version; hopefully you are using at least version 1.5.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarify conventions:

JUnit 3.8 - methods must begin with testXXX and extend TestCase.
JUnit 4.0 - annotate with @Test but no naming conventions

Maven Surefire - class names must be of form TestXXX or XXXTest or XXXTestCase. This is true whether you are on JUnit 3.8 or 4.X
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic