aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes In order to run junit 4.8.2 in maven do we need to have the folder  src/test/java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "In order to run junit 4.8.2 in maven do we need to have the folder  src/test/java?" Watch "In order to run junit 4.8.2 in maven do we need to have the folder  src/test/java?" New topic
Author

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

ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
Hello,

How do i tell JUNIT where my directory is?

I am using Maven.

Thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Sep 02, 2011
Posts: 60
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

Joined: May 14, 2008
Posts: 5827
    
    7

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.


JBoss In Action
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
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

Joined: May 14, 2008
Posts: 5827
    
    7

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

Joined: Sep 02, 2011
Posts: 60
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

Joined: May 14, 2008
Posts: 5827
    
    7

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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
 
subject: In order to run junit 4.8.2 in maven do we need to have the folder src/test/java?