Category Archives: Java

Spike: Unit Testing Static Methods

Previously we began discussing how great it is to use mocks and stubs. We showed how you can use dependency injection to set a stubbed out service instead of the real one. We also reviewed how you can use mocks to verify methods were acted upon from withing the method under test.  However you may come along a scenario where you need to test a method that requires you to call a static method on some other object. Regular mocking won’t suffice. Now it’s time for PowerMock

PowerMock is a nice add on to Mockito (and others) that supercharges what you can do with your tests. Continue reading


Coffee Notes: Spring & JUnit – What you Don’t Know

Over on Technophile Blog, Gordon Dickens posted a couple notes on Spring and Junit. With examples and comments Gordon review 2 features in Spring. One dealing with Default Context files and the second area is spring aware context files.
Gordon discusses:

1 Default Searching of Context File(s)
1a. No File Specified
1b. File specified (without a starting Slash)
1c. File specified with a Starting Slash
1d. Multiple Files

2. Spring Aware Test Options
2a. Autowiring Beans
2b. Transactional Test Methods
2c. Profiles – Evaluating Environment
2d. Timeout, Repeating & Invalidating Context

Nice features and easy to follow examples. Head over to Technophile Blog for the full story

http://gordondickens.com/wordpress/2011/01/07/junit-spring-what-you-dont-know-about/


Code Koans, Katas and Dojos

Developer groups are fantastic ways to enhance and hone your skills. Most of the user groups I’ve been to are great. Typically have good turnout, good presentations etc. Then there are developer conferences like No Fluff Just Stuff, Code Mash and others. What I like about those events is that there seems to be more hands on or more detailed conversations. Developers seem to group up and dive into topics in more detail in random open-spaces meetings. Unfortunately these events are only once a year

Where can we find presentations on new materials and actually work with other developers on the topic to build and hone our skills.  I stumbled upon a few similar Ideas I’m really beginning to love.

First is this idea of a Koan. A Koan is a Zen Continue reading


Unit Testing with Stubs and Mocks

Unit testing focuses on testing only the logic in a particular component without exercising logic in any dependent objects. This is often difficult as code is inherently dependent on other code. Developers can utilize techniques such as dependency injection, stubs and mocks to decouple code and execute unit level testing, but first it helps to understand what these techniques are. Continue reading


Spike: Prototyping with HSQLDB

Spike: Prototyping with HSQLDB - Tutorial by Christopher GrantI like doing quick prototypes but often when I come back to the code after awhle I forget about the database. Maybe I’m on  anew system that dones’t have the right Database locally or maybe I forgot to save off the schemea. Either way, my code is nice and neat in SVN but my DB isn’t.

So to counter this I’ve been looking at in memory DBs like derby and HSQLDB. At first I wasn’t sure what I was getting into but now I love it. These tools make prototyping quick and easy with little code.

I whipped up a little dev spike and thought I’d share it with you all. Continue reading


Coffee Notes: The Domain Test Values Class

Coffee Notes: The Domain Test Values Class - Blog Entry by Christopher GrantHere’s an interesting clip on optimizing the way you write Unit tests. In his Blog entry, Dave Bower presents a pattern for using meaningful terminologies rather than literals in your tests.

    http://manbuildswebsite.com/2010/12/20/domain-test-values/

While literals are typically a code smell in stadard coding, I personally have seen quite a few in unit tests. Applying the solid coding practices Brower presents will make your tests easier to read and maintain.


My Development Spikes – Now on Google Code

Development Spikes - Blog Post by Christopher Grant - A Spike is a term used in agile methodologies for time boxed periods of research and development. Development spikes are a great way for developers to work out core ideas before implementing them in real applications. Over the years I’ve found development spikes to be a useful tool in understanding technologies, as well as demonstrating concepts to others. Rather than wait for some work project to need something I began proactively coding  simple tutorials or trying out a new patterns. As new projects came up I was able to go back to my cache of spikes and pull out some experiment I previously did to see if it applied.

Months ago I canceled my contract with a hosting provider and of course, realized afterward I had stored many of my development spikes there and ultimately  lost them. I’m working to slowly rebuild my cache.

Since I used to use those examples in various training sessions or presentations, I thought this time I would post my dev spikes for all to use.  So if you head over to http://code.google.com/p/grant-dev-spikes/ you should be able to access my new cache. While there may not be a ton there right now you can follow along as I add simple demonstrations, tutorials and development spikes. If you have suggestions on examples you’d like to see, or if you’d like to contribute directly let me know crgrant at gmail.com


Follow

Get every new post delivered to your Inbox.