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. http://maven.apache.org/settings.html

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.


Thursday, 22 August 2013

Maven Troubleshooting FAQs and Tips

We use Maven in the Java For Testers book.

Once you have Maven running it tends to work fine. You mainly experience problems when you initially install it, at the point when you know how to nothing with Maven.

I listed the main steps and actions I take in a pdf which I released to Slideshare and Google Docs.

Tips are:
  1. Debug maven issues from the command line, not from the IDE
  2. Read the Error Messages
  3. Work through "Maven in 5 Minutes"
  4. Compile without running the tests
  5. Try and download manually
  6. Set the proxy settings
  7. Read the official FAQs
  8. Find more hints and tips lists
  9. Force an update of the dependencies
  10. Delete your local repository cache
  11. Force a purge of the local repository
  12. Look at the effective pom and settings
  13. Use the dependency tree view
  14. Experiment and try and fix it yourself
Nothing Earth shattering there. But all things I've done, and told other people to do, to fix their Maven setup.

Friday, 14 June 2013

Some Handy IntelliJ Code Completion Keyboard Short Cut Tips

Assuming you chose IntelliJ as your Java IDE, and why wouldn't you?

There are a few tips I want to pass on for helping with code completion.

I assume you already know Ctrl+Space to start code completion.

In the code completion pop-up you can use Ctrl+Q to see the JavaDoc help for that method.

And if you get stuck with the parameters for a method then Ctrl+P can show you what options are available.

Wednesday, 12 June 2013

How do I get started installing what I need to write Java?

If you want some help getting started with Java then I created a Free online course that includes the setup instructions for:
  • Java
  • Maven
  • Ant
  • an IDE (Eclipse and IntelliJ)
It even has instructions for writing your first test.

Admittedly the course is designed to get you started writing web tests using WebDriver, but in Java. So it has to cover getting started with Java as a prerequisite.

Monday, 10 June 2013

JUnit ExpectedException Rule

JUnit has a new way of testing for Exceptions.
Back in the day, we used to add the expected parameter to the @Test annotation.
@Test(expected = InvalidPassword.class)
But now, JUnit has a new @Rule
@Rulepublic ExpectedException expected = ExpectedException.none();
And you configure the ExpectedException in the @Test method:
expected.expect(InvalidPassword.class);expected.expectMessage("> 6 chars");
Very useful if you want finer grained control over your Exception testing.
You can find out more on the JUnit github.

Friday, 7 June 2013

Which IDE should you use for Java?

There are a whole bunch of free IDEs out there that you could use with Java:

  1. IntelliJ
  2. Eclipse
  3. Netbeans
And there are more, I just listed those that I have tried. You can also use Text Editors as an IDE, some of those even have code completion now.

So which Java IDE should you use?

Well, I use IntelliJ. I even paid for it, which is something that I never thought I'd do for a Java IDE - I do use it for pretty much all my development work: JavaScript, HTML, XML etc.

But that doesn't mean you should use IntelliJ

First thing I recommend you do is:
  •  look around and see what people on your team are using. 
Because chances are you are going to need some support when you start learning Java, and chances are the first people you are going to ask will be the people on your team. 

If you are using the same IDE as the people you are asking for support then you have one less barrier getting in the way, and one less thing adding noise to your problems.

Warning: Don't ask people what you should use. Instead ask what they use. but do it individually, and in secret otherwise you'll start an IDE development flame war

All the IDEs are very good. Some will work faultlessly on your machine, and some won't work. So if you 
encounter initial setup issues, then try another IDE, you might find your problem vanishes. 

Over time you will start to get a feel for what problems are caused by your code, and what problems are environmental related to your machine + your IDE.

If you want help getting started with Eclipse or IntelliJ then my Free Online Start Using WebDriver course has videos explaining how to install Java, Maven and Eclipse or IntelliJ

P.S. But I use IntelliJ.
P.P.S The android dev kit was based on Eclipse, but the next version uses IntelliJ