I have a question about the TestNG configuration files and Maven project structure, I would like know the best practices to save the configuration files.
E.g. I have use a testing.xml is a file which uses several classes to create a Suite. If I use the java application archetype of maven, where is the best place to save the xml file (testing.xml)?. I have taken a look to Maven standar directories, but I do not find anything about this issue.
src/test/resources
you can create a folder test-suites here and have different suite xml's here.
Related
I have a Java Spring application with unit tests in the directory
src/test Specifically src/test/com/client/rest
I'd like to add a child directory here, something like
src/test/com/client/rest/controllers
Which contains the unit tests for all controllers of the application. I created a file in this directory with a "#Test" end-point, but did not do anything to POM.xml. When I run mvn clean package I get the following error
The goal you specified requires a project to execute but there is no POM in this directory [path]. Please verify you invoked Maven from the correct directory.
I tried adding this new directory as a testResource element under build in POM.xml, but that did not work. Prior to adding this new file, the tests ran fine with <testSourceDirectory>src/test</testSourceDirectory> under the build element.
How do I properly integrate this new JUnit directory into Maven?
EDIT: I moved my new file to the standard parent directory where the other JUnit test files are (src/test/com/client/rest) and it seemed to register fine. What is the best practice for storing JUnit class files, and is it worthwhile to try to create new child directories for organizational purposes?
I think the error comes from just running the mvn command from somewhere other than your project root.
How do I properly integrate this new JUnit directory into Maven?
Follow the Maven Standard Directory Layout - https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Your tests should be under src/test/java/com/client/rest/controllers . They should then be discoverable and just work without any additional Maven configuration.
What is the best practice for storing JUnit class files, and is it worthwhile to try to create new child directories for organizational purposes?
It is worth organizing your tests. I think the piece you're missing is that you are writing tests in Java so you need to organize your tests with both directories and packages. So a test located under src/test/java/com/client/rest/controllers would have a package of com.client.rest.controllers .
I'm wondering what is the best way to organize Spring Configurator directories in my Maven project ? I wan't to have prod,dev and test config sets with seperate *.xml and *.conf files.
And also I'd like to have a seperate master *.xml file that is used in every config set.
Do I have to place *.xml and *.conf files in seperate directories ?
Or could I just places them in the same dir , like so:
spring/
test/application.xml
test/params.conf
dev/application.xml
dev/params.conf
prod/application.xml
prod/params.conf
Thanks for help :)
Place them in a directory structure in a way that no redundancy exist on classpath. Eg: if your code searches for */application.xml file and you have all 3 on the classpath it will cause confusion
Also leverage the use of Maven build profile and assembly plugin. Configure it such that only relevant files are packaged for each build profile.
Hi all i have very rare problem which needs to be solved.
Problem/issue:
I have a dynamic web project which is already built and i have war file of that project.
I need to apply some customizations on top of the war file given to me.
Using maven or ant am able to compile the custom code written by me and able to add produced class files to the war file.
But the this is happening for final war file build.
when i want to test my code in eclipse. the war file build and deployed in jboss plugin contains only the class files produced out of java files written by me..........
Please help me how can i modify the .classpath file of my project so that a jboss publish can build a war file using the dependent war file which can run on eclipse-jboss to test my custom code....
Advance Thanks.....
Not a rare problem.
What you need to combine two web applications (wars) together. You have your customization war on which you need to overlay the existing web application.
It looks like you have already solved it from build perspective and looking for Eclipse support. To my knowledge, Eclipse lacks support for this. You probably need to manually do the necessary configuration to make this happen.
It looks strange to me to have two WAR files.
Perhaps you have to consider to package your customizations in a JAR and inserting that jar in the original WAR file.
Otherwise, another solution, and what I do often with open-source project to customize is to have three projects in your workspace.
PRJ-src (with your original sources/JAR/WAR)
PRJ-custom (which depends of the previous one); This project contains only the new classes or custom spring xml files (with injection of my own classes)
PRJ (the merge of the two previous projects)
I create an Ant task in the 3rd project which takes the 1st project (PRJ-src) and merge with the 2nd project (PRJ-custom). This is possible to do so with Maven as well.
Then this is the only project I deploy in my app server (tomcat / jboss).
In the eclipse directory, there is .classpath file. What's the purpose of this file?
I have ant build.xml available, why Eclipse still need its own?
Eclipse has its own mechanism for building your project. The .classpath file contains information that the IDE uses to create the classpath used at build-time, runtime etc. You can directly edit this file if you want but it is created by the IDE based on the settings that you provide via the project properties dialog.
There is Ant integration within Eclipse insofar as it provides you a specific editor for build files, but it can't use any of the information in the build file for its own builders. Ant files are custom, so there is no way Eclipse could know what info to use.
The reason for this is that it doesn't matter if you have an Ant file or not. The reason for the presence of this file is that this is a Java Project, and the corresponding Project nature always generate such a file. Create a normal Project (New->Project->General->Project) and you'll see that there is no .classpath file.
In general I would recommend to split those functionalities in separate projects, that means one Java Project for developing, one non-Java-Project for executing your Ant scripts.
HTH Tom
Is there a best practice for where configuration files should be stored in a Java project. The file type is a Java properties file in this case, but I do use other file types in other projects.
Would the recommendation vary from stand alone application(.jar) to web app(.war)?
You'll find that many open-source projects follow the directory structure used by Maven. In this setup your application source code is kept in src/main/java, application resources, including properties files, in src/main/resources, and other config files in src/main/config. Files related to unit tests use a similar directory structure; src/test/java and src/test/resources.
Personally I tend to use this layout because of its widespread use. I also keep an "etc" directory beneath the project root to house files that aren't directly related to the application. For example, I keep configuration files for PMD and Checkstyle in etc.
In general a common practice is to have a resources directory for configuration files which is copied into the build artifact by the build process. Maven uses this in its default project structure. Within the resources directory, you might also have a META-INF directory and/or a WEB-INF directory in an application packaged as a war.
I use:
META-INF/ for jar files
WEB-INF/ for war files