Friday, 20 September 2013

FAQ: Why do I only see test that fail in IntelliJ and not the tests that pass?

When you run your tests in IntelliJ you may have seen an output where only the failing tests are shown in the run pane tree.

In the above run I have 302 passing tests, but only 1 failed.

Where are my failing tests?

All IDEs offer a massive amount of power and functionality sqeezed into a tiny GUI. So your going to miss things. And one thing people miss, and I've missed it too, is the "Hide Passed" icon.

When this icon is selected you'll not see the passing tests, this allows you to focus on the tests that provided information i.e. 'failure'

If you want to see the passing tests, then click the icon so it is not selected.

Thursday, 19 September 2013

Maven settings.xml - global and user-specific

Sometimes you have to amend the Maven `settings.xml` file to add a proxy or various repositories.

I had to do that a couple of days ago when experimenting with a 3rd party library.

What I sometimes forget, is that there are two `settings.xml` files. Now I shouldn't forget this, because it is quite clear on the Maven Apache site.

But I do.

The settings.xml file in

  • `%M2_HOME%/conf/settings.xml` is the global settings.
  • your `.m2` user directory is your user-specific settings.
    • This file doesn't exist until you create it, which might explain why I forget about it.

Duplicate settings in the user-specific file, override the settings in the global settings.

I was reminded of this because of the permission schemes in Windows 7 which wouldn't let me save my global settings without upping my permissions to admin.

You can see the combined settings if you issue the command:

mvn help:effective-settings

Some useful references:

Wednesday, 18 September 2013

Do "Enable Auto-Import" in IntelliJ for "Maven projects need to be imported"

If you see the "Maven projects need to be imported" popup in IntelliJ, then do click "Enable Auto-Import".

You very often see this when you first create new projects and it is easy to miss. But many of my "Why isn't it finding this class" and "Why didn't it import that" queries, are because I haven't noticed the popup sitting patiently in the top right, waiting for me to respond.

Very often the first time you type `@Test` and you know you added JUnit as a dependency, and it runs fine from the command line, but IntelliJ doesn't like it.

If you miss the popup then you can still set the properties using the IntelliJ options

Tuesday, 17 September 2013

Chapter on Date and Time added to Java For Testers

I just added a chapter on Date and Time to the "Java For Testers" book.

In the production environment in the main application, we very often use the Joda-Time library. But I'm trying to keep coverage of 'libraries' out of scope for this book, to make it easier for people to get started, and so that they build knowledge and experience with the inbuilt features.

Relying too much on external libraries often means adding another library into the code-base when all that is really required is a quick wrapper around existing core Java.

The chapter covers basic examples of:
  • timing how long a set of code takes to execute
  • creating unique ids and names for files
  • formatting dates
  • date arithmetic and manipulation
I frequently have to format dates in different ways, when I'm generating test data for application testing.

I time the how long code runs, when I'm writing simple performance tests. I often use nanoTime to do this.

I very often create unique file-names using the value returned by currentTimeMillis. In the book I provide examples of simple ways to convert the numeric file names into alphabetic characters. I sometimes generate unique usernames for test data using currentTimeMillis.

We also cover basic date time arithmetic in the chapter. A very useful thing to be able to do, when generating random data.

I think I've covered the basics of Date\Time for the core Java classes well enough for people to start using it in their tests.

I've only ever had to drop down to Joda-Time once or twice in my career. I encourage you to experiment with the in-built Date Time functionality, before bringing in an external library. You might be surprised how much you can do.

  • `System.currentTimeMillis`
  • `System.nanoTime`
  • `Calendar`
  • `Date`
  • `SimpleDateFormat`

Friday, 13 September 2013

Support Page for Install Chapter on JDK, Maven and IntelliJ

I have left the install chapter in "Java For Testers" to the end, since the installation is pretty simple and really involves working through the official install processes.

But, sometimes things will go wrong.

So I have created an install support page on this site.

It links to the official documentation, and has some 'example' install videos, with links to other troubleshooting guides.

If you experience any issues installing the tools for "Java For Testers" book then let me know.

f you find any useful resources that helped you get started, then let me know and I can add those here too.