Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Monday, March 21, 2016

Maven command to run tests in a selected module and ignore failures and redirect output to a file

This is useful when I want to see all the failed tests, and I want to have it in file so I can easily navigate thru entire output - for example to search for errors.
mvn -f system-tests/pom.xml -Dmaven.test.failure.ignore=true clean install > myout.txt

Monday, January 25, 2016

Maven command to run System tests from CI

I keep system tests in a separate module. Command run by CI to run them is following:
mvn -X -B -f system-tests/reservationsWS/pom.xml --fail-at-end verify install deploy:deploy

Maven install skipping tests

It speeds up install when I just want to recompile everything:
mvn clean install -DskipTests -DskipITs -DskipSystemTests

Monday, October 26, 2015

Documentation for Maven archetypes

I don't start new projects in Java often. Each time I do it I have to go thru terribly written Maven documentation. 10 maybe 13 years ago when I was writing my first projects with Maven documentation was terrible and absolutely nothing has changed. If I didn't know what I am looking for I would be terribly lost. Even when I know what I want it takes me huge amount of time to figure out how it is labeled in Maven project. Have a look at a difference between Simple and Quickstart project archetypes.
  1. Simple: An archetype to generate a simple Maven project.
  2. Quickstart: An archetype to generate a sample Maven project.

Wow, now I learned something definitely. Guys, what is the difference between simple and sample. Which archetype should be used just to create a playground application to write some code and unit test it. I mean library project type. I just want to run tests on my code to check something.
What a wonderful explanation we get when we dig into a given archetype. When you click on Simple project you see this. What is it - empty page. Maybe some explanation of what do I see here. Not to mention that I would expect to see a in depth explanation of when should I use it and why should I use this one.
I am speeches, how can you have something like that. The sad part is that Maven is not the only project in Jave world that is terrible in documentation.
To answer my question about which archetype to use. I recommend using quickstart, that will create a following project structure.
project
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- App.java
    `-- test
        `-- java
            `-- AppTest.java

Thursday, May 3, 2007

Unit Testing with Groovy




So we know what the Groovy is and how to eat it. Now it is time to do something useful in terms of methodology. I'm agilist and the thing that I do after knowing constructors and reductors is how to test it. Again Groovy is really helpful, and easy to use. So, you don't need to add additional libraries or do some hacking to use tests in Groovy - they are provided in a default installation. By the default installation i mean get a Groovy from local ftp untar it and there it is ready to be used. So here is a simple example:

Create a class Square.groovy

class Square{
def square(x) {x*x}
}


Create a class SquareTest.groovy

import Square

class SquareTest extends GroovyTestCase{

void testSquare(){
Square square = new Square()
assertEquals( square.square(3),9)
}
}


be sure that both classes are in one catalog. In a command line just type:

groovy SquareTest.groovy


and see the result - everything is fine. It is the easiest xUnit framework that I've seen.
One thing about classes in Groovy - they are public by default, same as methods.

Now let's say that we want to create a framework in maven or we already have one and we want to add some Groovy classes or Groovy test classes. This task is more complicated - because of maven, it is a good tool but sometimes when you search in a xml files for a bug it it terrible, I hate it, but again it is like 200 times better then ant.

so to create a maven project (I'm using maven 2.*) just type:

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app


Now goto my-app and edit pom.xml add:

<dependency>
<groupid>groovy</groupid>
<artifactid>groovy-all</artifactid>
<version>1.0</version>
<scope>test</scope>
</dependency>


create a folder groovy in my-app/src/main directory and in the my-app/src/test. In other words just in this same place as java folder. And put a *.groovy class there. Go back to the my-app directory, and run:

mvn groovy:compile


to compile main classes.

mvn groovy:testCompile


to compile test classes.

You might ask "Cool, but is there a way to compile classes just by calling normal mvn install or mvn compile?". Yes there is, just add this code to your pom.xml file:


<build>
<plugins>
<plugin>
<groupid>org.codehaus.mojo</groupid>
<artifactid>groovy-maven-plugin</artifactid>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


Now every time you compile or run tests also groovy classes are going to be included.