Working with slow modules in Maven is a problem. People will not build the module as often as they need and they will therefore not find problems as early as they could.
A solution could be to separate some of the slow stuff to a separate module. One separation can be to have a specific module for slow tests. This will, however, not solve the problem, that the module is too slow.
A solution to the problem could be to only include it in the execution when you invoke a specific Maven profile. This would separate the execution of a slow module from the execution of the rest, fast, modules.
Let me implement a simple example with two modules. There is the first module, the application, that we always want to build. It has fast unit tests and it is therefore not hindering to execute it often. Then there is the second module, the acceptance tests. It requires you to fire up your application before it can be executed. It is therefore dead slow. As a developer you will probably only want to execute the acceptance test module now and then.
Let me show you one way to achieve this.(more...)
The answer to this question is: It is as easy as to run it from Maven. Depending on your background, perhaps even easier. The reason for this is because we run Cucumber from a JUnit runner. That is as a unit test with a specific runner. Maven or Gradle really doesn't have anything to do with this. It all boils down to the need for a Gradle project that can build a Java project. A Java project that has a unit test.(more...)
I have been using Maven for a long time. I used to use Ant and it took me a while to get used to Maven and accept the Maven way. Reading a blog post from Neal Ford Why Everyone (Eventually) Hates (or Leaves) Maven got me thinking. He talks about the popularity of 4GL, Fourth Generation Languages, during the 1990s and why they never really took off. The idea was great, but they were not able to solve the entire problem good enough. They solved perhaps 80% easily and the rest was harder and the last part was even harder to solve. The customers want this last part as well and that is the reason why we use general purpose programming languages today.
I used Paradox to build a system for a customer a long time ago. I was able to solve most of their problems.
One thing though, there was an error situation and the customer demanded a correct error message. My problem was that it was a system error that came from the runtime environment that I couldn't control. My solution? To patch the binary that I delivered my application with. I replaced the error message with another message. I was lucky, the message I needed was one character shorter so the binary format was never changed. I am not sure that it was legal, I never asked Borland about it. But the error message became correct and the customer was happy and so was I.(more...)
How can you get the build directory in your maven plugin?
The answer to this question may seem simple, just refer to
./target in your plugin and everything
should work. This works in the simple case. It does, however, not work when you are using you plugin in a multi
module project. Your plugin will not know where it is executed and cannot refer to a subdirectory relative to the
directory where Maven is invoked. It may be executed in a multi module build or a single module.
In my assignment as a Configuration Manager, CM, I need to script a lot of things. I also need to automate the execution. Most of the stuff I build is built using Maven. Some is built using Ant. Both Maven and Ant are easy to run from TeamCity. But none of them are very flexible when it comes to scripting. Maven isn't designed for it and Ant is missing some features and get very verbose. The most important feature I am missing in Ant is repetition.
I saw a panel debate a while ago where three guys were discussing their favorite tools. The tools represented were Scala, Ruby and Groovy. One thing that I remembered from that session was that the Scala guy mentioned that he often used Ruby when scripting. My problem with using Ruby is that I don't have control over my execution environment. I can't install tools in it. I am not interested, either, because that wouldn't scale very well since the installation done on our build servers are done manually. I can, however, expect that Maven and Ant will work.
Given that I can expect Maven to work, I decided to try to execute a Ruby script from Maven. It turned out to work very well. I was able to reduce the size of an Ant script with 50% on my first attempt. In my opinion, the readability increased a lot. I was able to write the script more or less as prose.
If you are interested, this is how I did.(more...)
Filed under: Maven, — Tags: Almost simplest possible, Simplest possible — Thomas Sundberg — 2013-02-24
Maven is a build tool for Java. You define a project with Maven, build and test your product.
Usually you hate Maven or you love it. Before you have understood how things work, you usually hate it. If you persist, then there is a chance that you will like it.
I have met many developers that claim that Maven is either "To complicated" or "Impossible to understand".
I have even been asked "Don't you feel dirty using Maven?" during a session at an Agile conference. My answer was "No, why should I feel dirty for using a good tool?" This question and an opinion stated at another conference triggered me to write this. I aim to show you how Maven can solve some problems, using baby steps and starting from the simplest possible solution that could work. My goal is to write an easy to understand getting started guide. If you think I take a too large step somewhere on the way, please give feedback and tell me where I take a large step. If you think my steps are to small, then you probably already know enough about Maven so you don't need this introduction.(more...)
Getting started with Selenium WebDriver may be an issue. You must write some code and get the code running. I have created what I think is the smallest possible solution that could work. It consists of two files, a project definition and the actual test.(more...)
What is JBoss Drools? It is a framework where you can create rules that defines when a specific action should be done. This could be done in code using conditions. Creating them using a rule engine can make it easier to combine many business rules with many actions.
I tried to get a JBoss Drools example up and running. It turned out that the examples I found on the web were either were very complicated, tried to solve all possible problems or was just incomplete. I ended up writing my own example where I have removed everything that I didn't find necessary.
I divided this example in two parts. First part is the simplest possible solution that could work, a Hello World. In the second part I try to do something that actually could be useful. I trigger a rule and instantiates a class that could perform some action.(more...)
The way Maven file structure is defined is a great way to separate unit tests and production code. Unit tests are fast. So fast that developers developing using Test Driven Development, TDD, doesn't have any performance problems when applying the Red-Green-Refactor cycle in their work. A large unit test suit is expected to be executed in seconds.
There is, however, no standard on how the files should be structured for slower tests (integration/acceptance/system et.al.). A common property for these tests is that they are slow. They often require a complete system setup in a known state. They use the filesystem, network, database and similar slow resources. Slow tests are normally not executed often. Developers seldom have the patience to wait for a build a long time before writing the next thing. Using them in a Red-Green-Refactor cycle is not practical. It takes too long time.
So what options do we have to separate the fast units tests and the slow tests? There are two main tracks that I have explored.
It works on my machine!
Ever heard that from a developer? I have, and it happens that the reason is that it actually works on their machine. It may also be the case that the order in which tests are executed matters. Test classes depends on each other and the order they are executed in is important. The solution is to execute the tests in random order so that any dependencies between tests are found and can be removed.(more...)
Test driving a project should result in a test coverage of 100% of the code. But how can we know what test coverage we have? Is it even important?(more...)
Filed under: Cucumber, Maven, Test automation, — Tags: BDD, Behaviour Driven Development, Behaviour Driven Development - BDD, Cucumber, Cucumber-jvm, Executable specifications, Java, POJO, Readability, SoapUI, Test web services, soap — Thomas Sundberg — 2011-11-16
An example is perhaps the best way to describe something. Concrete examples are easier to understand than abstract descriptions.
I will show how SoapUI can be used to test a web service. I will also show three different tools that can be used to control SoapUI. This tool chain can easily be made a part of your continuous build.(more...)
Filed under: Automation, Cucumber, Maven, Selenium, Software development, Test automation, — Tags: BDD, Behaviour Driven Development, Behaviour Driven Development - BDD, Cucumber, Cucumber-jvm, Executable specifications, Java, Page Object, Parameterized JUnit, WebDriver — Thomas Sundberg — 2011-10-18
Selenium a great tool for testing web applications. The current version, Selenium 2, is a merge between Selenium and WebDriver. I will walk you through an example where we test a web site using Selenium in a few different ways. This is the same example as I demonstrated at Scandev on tour in Stockholm 18 October 2011.(more...)
I just had test in a Maven build fail with
java.lang.OutOfMemoryError: Java heap space(more...)
Have you ever wondered why your Maven project doesn't find and execute your tests?(more...)
Filed under: Maven, — Tags: Automation, Install libs in Maven — Thomas Sundberg — 2011-06-10
Suppose that you have a dependency that looks something like this:
<dependency> <groupId>foo</groupId> <artifactId>bar</artifactId> <version>1.0</version> </dependency>
that can't be resolved and the build fails with the error message below:(more...)
Creating an executable jar from Maven is not really hard.
This example will show you how you can include stuff in a jar and make it executable while not including stuff that is needed only during the build.(more...)
Chasing the warning:
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!(more...)
We had a problem in my current Java project. Whenever somebody wrote a comment using Swedish national characters, åäö or ÅÄÖ, and later tried to build the system with Maven we got the error:
unmappable character for encoding UTF-8(more...)
Filed under: Maven, — Tags: Ant, Antrun, CI, MAVEN_OPTS, Test automation, maven.test.failure.ignore — Thomas Sundberg — 2011-02-11
A friend of mine needed an example of how to use the Antrun Maven plugin.
This is a simple example that will show how to execute any Ant targets from a Maven build during the install phase.(more...)
Maven has a default behaviour that it fails a build if a test fails. Hudson and Jenkins turns this default behaviour up side down. Maven builds that fails are marked as unstable instead of failed. This behaviour may be surprising to anybody setting up a Maven build.(more...)
I want to build a Hello World example for JBoss ESB using Maven instead of Ant. The original example bundled with JBoss ESB is using Ant. I have created a pom.xml that will do all the magic and re-located the example files to fit into a Maven structure.(more...)
I want to to create a very simple web application using Spring. I want to create it using Maven as build tool.(more...)