mentby.com
Blog | Jobs | Help | Signup | Login

Maven + JUnit, what's the best approach?



I'm new to Java and maven and currently in the process of building the
entire infrastructure for java development in the company.

i'm not quite familiar with JUnit, but i know maven makes it easy for you by
creating default test tree and test classes in each project.

where can i read about best practices regarding writing unit tests for my
java apps using JUnit with MAVEN?

thanks.

--
Eyal Edri


Eyal Edri Tue, 29 Dec 2009 05:21:41 -0800

Hi,

You should follow the folder structure

src/main/java ...
src/main/resources

src/test/java ...
src/test/resources

Further details here: http://maven.apache.org/guides/introduction/introduction-to-[..]

Just write them as usual JUnit Test Cases....

Than you can simple do mvn test to run the test cases or use
Eclipse/Netbeans etc. run them from the IDE instead...

Kind regards
Karl Heinz Marbaise
--
SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
Hauptstrasse 177                         USt.IdNr: DE191347579
52146 Würselen                            http://www.soebes.de


Karl Heinz Marbaise Tue, 29 Dec 2009 05:54:22 -0800

Start with:

http://maven.apache.org/guides/getting-started/index.html http://code.google.com/p/t2framework/wiki/JUnitQuickTutorial

I you are building an infrastructure, aside from JUnit and Maven
knowledge, you will (probably) need to install, in order of importance:

1. Version control system such as Subversion
2. Maven ropository, such as Apache Archiva, Artifactory or Nexus
3. Mailing list manager, such as Mailman
4. Issue tracking system, such as Trac
5. Continuos integration system, such as Apache Continuum

Regards,
Ognjen


Ognjen Blagojevic Tue, 29 Dec 2009 05:59:00 -0800

thanks,

actually i've already setup a few things:

   - artifactory
   - hudson
   - scm (tesing accurev)
   - maven2
   - issue tracking is currently bugzilla, but might be jira

i'm looking at the default test classes maven creates, are they obsolete?
i saw that maven added junit 3.8.1 instead of 4.x as a dependency and
auto generated this code:

*import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class DbUtilTest
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public DbUtilTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( DbUtilTest.class );
    }

    /**
     * Rigorous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }

}*

should i change the junit in the pom to 4.7?
in some junit examples they use annotations (@Test), which doesn't work with
that code..

i'm a bit confused...

--
Eyal Edri


Eyal Edri Tue, 29 Dec 2009 06:12:06 -0800

Hi,

Maven does not create Test Classes...

Yes you should, cause if you use JUnit 4.X instead of 3.8 ?

You have to use JUnit 4.X instead and configure to use Java 1.5 at least
to be able to use Annotations...

Add a part
<build>
    <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <source>1.6</source>
                     <target>1.6</target>
                     <debug>true</debug>
                 </configuration>
             </plugin>
    </plugins>
</build>

in your pom to compile with 1.5 or as in this example with 1.6...

Kind regards
Karl Heinz Marbaise
--
SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
Hauptstrasse 177                         USt.IdNr: DE191347579
52146 Würselen                            http://www.soebes.de


Karl Heinz Marbaise Tue, 29 Dec 2009 06:16:03 -0800

i had to use the mvn cli to update the junit from 3.8.1 to 4.7 and run
mvn eclipse:eclipse.
    only then i was able to use the code from the example.

thanks.

--
Eyal Edri


Eyal Edri Tue, 29 Dec 2009 06:50:21 -0800

IMHO, accurev is a pile of ____ esp if you want to use Maven.  There are
some architectural decisions that they made which make use with Maven a
pain.

Subversion is great with Maven, and it's free too....

Also having migrated our 11 years worth of source control from Accurev to
Subversion (including writing a tool [which my employers will not let me
publish] to extract the full history into Subversion) I would not personally
touch Accurev with a 1000 foot barge pole.

I know others feel differently, and these are my personal opinions, but
anywho, just thought you'd appreciate the feedback

-Stephen

P.S.
  1. You cannot export a tree into a subfolder of a workspace (makes using
the maven release plugin a nightmare)
  2. You cannot have a workspace as a subfolder of another workspace (makes
aggregator style projects a pain... You can solve this by using
include/exclude rules and some partial view stuff... but that only works if
you only use one depot...)
  3. Snapshot/workspace names must be unique at any point in time... and you
cannot delete snapshots... makes tagging a pain... try re-rolling a release
with maven-release-plugin
  4. AFAIK, Maven release plugin does not work yet with Accurev (as the SCM
support for maven was not where it needed to be before we ditched Accurev) I
had written an SCM implementation [which I cannot share] but it was
impossible to get it to work with the release-plugin's workflow


Stephen Connolly Tue, 29 Dec 2009 08:32:05 -0800

I ran away from starteam into accurev.... :(

is there any other good managed (commerical) SCM out there that works with
linux?

Eyal.

--
Eyal Edri


Eyal Edri Tue, 29 Dec 2009 10:11:32 -0800

Hi,

Why do you need a commerical tool ? Why not using Subversion ....

Greate community, really good documentation (for free)...which is
supported by many many tools (IDE, Maven, Hudson, etc. )...

And what did you understand under "managed" ? Support contract ?

Kind regards
Karl Heinz Marbaise
--
SoftwareEntwicklung Beratung Schulung    Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise        ICQ#: 135949029
Hauptstrasse 177                         USt.IdNr: DE191347579
52146 Würselen                            http://www.soebes.de


Karl Heinz Marbaise Tue, 29 Dec 2009 10:16:34 -0800

yea..by managed, i meant support from a vendor.

You don't have to convince me.. i'm the developer :)
you need to convince the r&d manager that going to put all the company's
source code
in an open source project, which if there is a problem... might not someone
to yell at :)

btw: don't fall off your chair.. but we've been using starteam 6 (from 2005)
so far...

but.., i hope i'll managed to convince them... i just need strong points..

if you say it works good with maven & hudson.. then it's a good start...

--
Eyal Edri


Eyal Edri Tue, 29 Dec 2009 11:35:26 -0800

CollabNet provides support contracts for Subversion.


Justin Edelson Tue, 29 Dec 2009 11:43:15 -0800

I suggest looking at Perforce.  It is the best SCM I've used (cvs, svn,vss, clearcase, pvcs, starteam, and a couple other no-names I can'tremember).


Jeff Jensen Tue, 29 Dec 2009 20:22:56 -0800



Related Topics

Post a Comment