TIL: Maven is Very Specific

This post was inspired by something I ran into at work the other day, and felt like it would be a good thing to share. It was definitely something that was new to me.

My tasks at work lately have been requiring me to go back and get our code coverage up for each of our existing services. The particular service that I was trying to work on was constantly having issues running from within IntelliJ. I could build with mvn just fine from the command line, but there was a handful of tests that were constantly failing for me.

So I contacted the person that wrote the tests and had a call with him. He quickly pointed out that the tests that weren’t running were marked as “integration tests” with a trailing IT at the end of the test name (i.e. someTestIT).

Me still being new to all of this, just accepted this at face value and moved on, assuming that surely it had to do with putting the IT at the end of the test name.

Yeah… About that…

Boy was it sure a lot of fun googling today for the answers as to why this was happening.

I was off down a hole trying to understand how “maven knows to skip integration tests”. Everything I kept finding had nothing to do with the naming convention I saw at work, and all of it pointing to some other maven plugin that you can use to enforce the skipping of integration tests.

I went back down to look at our code and surprise, nothing of the sort was in our code.

So how was this happening? I started playing around with it on my own to see if I could figure out what was going on.

So I started out by creating a new dummy mvn project (you can find it here). In it I created two new tests:

  1. UnitTest
  2. UnitTestIT

I went to go do the build and ran into my first issue (surprise). I wasn’t aware that you needed to actually define the version of java to be used. Oops! So I popped this into my pom file and on I went (source):


Finally it was building, and I only saw one test being run! Huh, so I guess it does have to do with the name? Just to make sure I went ahead and renamed the UnitTestIT to UnitTest2 and re-ran it again.

…but still only one test was running. Really strange. So I went ahead and changed UnitTest2 to DummyTest and ran again… Both tests were running. Finally change DummyTest to DummyTestIT and run once more… one test executed.

So I went searching again, and what a surprise: mvn has very strict rules for test naming convention. Oops. Essentially by ending the file with an IT, we’re cheating the system a bit and making mvn think that it’s not a test file (even though it’s right next to all of the rest of the tests).

This is a neat little cheat to mark a test that shouldn’t be run at compile time, but might want to be run manually through the IDE.

💚 A.B.L.