Friday, 15 June 2012

java - How to add classpaths for unit tests in maven ? -



java - How to add classpaths for unit tests in maven ? -

i using maven create simple application , writing unit tests it. new both using maven writing unit tests junit.

my directory construction follows :-

the source code classes used in project in directory : -

project-name/src/main/java/com/somename/app/packagename

main file (which contains static main method) in :-

project-name/src/main/java/com/somename/app/app.java

the default unit test provided maven in :-

project-name/src/test/java/com/somename/app/apptest.java

now, have added unit test in above directory (in apptest.java) there , unit test needs access classes defined in "packagename" directory described above.

if simple commandline , have added classpath directory when compiling , running application.

how should same in maven ? also, there alternative adding classpath straight in maven ?

when using maven standard directory layout (which recommend maven conventions), next directories part of classpath when running tests:

src/main/java src/main/resources src/test/java src/test/resources

so there no need manually adjust running tests. mvn test command want.

java unit-testing maven junit

No comments:

Post a Comment