#a1

A set of testing tools

Petri Kainulainen posted “12 Tools That I Use for Writing Unit and Integration Tests,” which does a pretty good job of describing a set of testing tools and approaches, including solutions in the following categories: Running Tests Mock and Stub frameworks Writing Assertions Testing Data Access Testing Spring It’s not comprehensive (nor does it claim to be), with no mention of things like TestNG, Arquillian, Liquibase or Flyway, or testing CDI in general (see...

1 minute(s) read

First steps: Structure of your first source file

This is what a class file ought to look like when you take your first steps writing java programs: public class YourAppNameHere { public static void main(String[] args) { new YourAppNameHere().go(); } private String iAmAField; void go() { System.out.println("Your code goes here!"); } void someOtherMethod() { // You can call this method from 'go' with: someOtherMethod() iAmAField = "Hello, World!"; } } In particular, copy/paste the main() method verbatim and don’t touch it. If you need access to...

2 minute(s) read

Use exceptions correctly

In this article we are going to address the common misuse of exceptions, more specifically those times when programmers fail to correctly propagate exceptions. Along the way, and most of this article, we will talk about the differences between runtime and checked exceptions and the ways in which it is appropriate to use them. Runtime exceptions There are two main differences between checked, or “normal,” exceptions, and runtime exceptions: Runtime exceptions don’t have to...

6 minute(s) read

Code Complexity

This morning, a user asked a question about determining the equality of three values on ##java. The code he offered as a test was as follows, roughly: boolean a=false, b=false, c=false; System.out.println(a == b == c); Rather than determining if the three values are equivalent, this code checks to see if a is the same as b – with the result of true – and then checks to see if this result is...

2 minute(s) read