MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
madhockeydad
Post subject: Maven Convention Unit Tests and Add Maven to Web Project  PostPosted: Nov 02, 2010 - 05:08 PM



Joined: Jun 28, 2010
Posts: 18

Hi

It is possible to select New -> Web Project and then enter a name for the web project and on that wizard is a section with a check box - "Add Maven Support". If checked this will create a standard MyEclipse web project with a pom.xml at the root level. The structure of the project will not be the Maven conventional structure but rather then MyEclipse structure with the proper changes to the pom.xml.

My question is using this approach where do the Unit Tests go (there is no directory named "tests" created) so that they will be executed automatically as would happen with the standard (conventional) maven structure?

If the tooling is going to support adding maven to a standard MyEclipse web project it seems like it should include the directories and/or mappings for the unit tests as well.

David
 
 View user's profile Send private message  
Reply with quote Back to top
support-neeraj
Post subject: RE: Maven Convention Unit Tests and Add Maven to Web Project  PostPosted: Nov 03, 2010 - 01:32 PM



Joined: Mar 03, 2010
Posts: 23

Hi David,
Please find the steps below. With this you can create a folder to store all your test cases. The changes in the pom.xml file will enable the test cases to be executed automatically as it happens in a conventional maven project.

1) Add a new source folder to the project (say tests) that will contain all the tests. You can do this using the project right click context menu->Build Path->New Source folder.
2) In the pom.xml file copy the following junit dependeny.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
3) Add the "testSourceDirectory" element under the <build> element as shown below
<build>
...
<testSourceDirectory>${basedir}/tests</testSourceDirectory>
</build>
 
 View user's profile Send private message  
Reply with quote Back to top
madhockeydad
Post subject: Not quite working  PostPosted: Nov 04, 2010 - 04:33 PM



Joined: Jun 28, 2010
Posts: 18

Hi

In my WAR project, the unit tests work when I add the JUNIT dependency with a scope of compile but not for a scope of test!!! If I use the scope of test I get the following exception (which shows it is not using JUnit with a scope of test):

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project DavidMultiWAR: Compilation failure: Compilation failure:
C:\Documents and Settings\ditdla\Workspaces\MyEclipse-8.6\DavidMultiWAR\src\test\java\david\test\DummyClassTest.java:[4,22] package junit.framework does not exist

C:\Documents and Settings\ditdla\Workspaces\MyEclipse-8.6\DavidMultiWAR\src\test\java\david\test\DummyClassTest.java:[6,36] cannot find symbol
symbol: class TestCase
public class DummyClassTest extends TestCase {
 
 View user's profile Send private message  
Reply with quote Back to top
support-neeraj
Post subject: RE: Not quite working  PostPosted: Nov 05, 2010 - 02:21 PM



Joined: Mar 03, 2010
Posts: 23

Hi David,
Can you please check the "Maven classpath container" (Maven Dependencies) in your project and verify if it has the Junit jar present in it. You can do this just by expanding the Maven Dependencies container in your project. If the jar is not present, please make some changes in the pom.xml file and save it. This will download the jar into the Maven classpath container. This should fix the above issue.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits