I have a rather lengthy drive to work each day (~1 hour each way) while listening to the nonsensical ramblings of my local sports radio one day it hit me like a ton of bricks: why was I listening to this dribble when I could be spending this time making myself a better developer. Thus began my search for some good technical podcasts to fill up my iPhone with.
I'm primarily a ColdFusion/Java developer and you'll see that none of these focus on either of those. I'm a big believer that no matter what language you primarily use there are tons of things to learn from other languages. I've used many things I've learned from listening to these in my day to day development.
While this list is far from complete its based on what I've discovered so far. If you have a favorite podcast that you think I missed please comment and let me know. I'm always looking for more good ones to listen to.
Software Engineering Radio (http://www.se-radio.net/)
I don't recommend listening to this one before you've had your coffee. This podcast can be quite dry at times but it is packed with excellent technical information. If you can get past the sometimes monotone delivery there is a lot to be learned from every episode. The topics covered here cover an extremely wide range of topics, I'd highly suggest looking through all their back episodes for topics that may be interesting to you.
Herding Code (http://herdingcode.com/)
Herding code is a .NET focused podcast that contains mostly interviews with other developers. The guests on Herding Code are usually top notch, and I frequently find myself going to the show notes on the website and researching a lot of the topics that come up. The hosts are also extremely knowledgeable and usually ask their guests great thought provoking questions. The topics discussed cover both open source and Microsoft specific topics which is a bonus in my book.
Pragmatic Podcast (http://pragprog.com/podcasts)
This podcast is another interview style podcast from the publishers of the Pragmatic Bookshelf books. This podcast is a great change of pace from the strictly programming related podcasts I usually listen to. Most of the time the interviews are for development specific topics, but I find the real gems are the ones that don't focus on development. For instance, Andy Hunt's chat on Pragmatic Wetwear (http://pragprog.com/podcasts/show/13) or Chad Fowler's chat on "The Passionate Programmer (http://pragprog.com/podcasts/show/26) were some of the best overall podcasts I've listened to.
Polymorphic Podcast (http://polymorphicpodcast.com/)
The Polymorphic Podcast is another .NET focused podcast. The host, Craig, does an excellent job of talking about things at an architectural level that will benefit developers from any language. This podcast also does a good job at providing its listeners with enough high level programming best practices and techniques that its worth listening to even if you are not a .NET developer.
On Software (http://www.informit.com/podcasts/channel.aspx?c=dadf92ca-3bdc-484e-9cd8-cbfe0cfc0de6)
This is a short video podcast that covers a very wide variety of topics. From JavaScript to Rails to Ubuntu this podcast covers it all. The episodes are all on the shortish side ~10 minutes or so and since they are video podcasts I don't recommend listening to them on your commute, but they are great for watching while you are eating your lunch.
Pluralcast formarly Elegant Code (http://www.pluralsight-training.net/microsoft/pluralcast/default.aspx)
Admittedly I haven't listened to nearly as many episodes of this one as the others, however, the ones I've listened to have had excellent technical content. Again, its another .NET podcast but David does an excellent job in breaking down the technical aspects of what he's talking about and seems very detail oriented which helps when explaining something in an audio format.
Railscasts (http://railscasts.com/)
This Ruby-On-Rails specific videocast may be unmatched in its technical content. Like the prior sentence implies, this is another video cast that is a great watch during your lunch hour. Even if you never have any intention to write a line of Ruby you'll be hard pressed not to take some of the ideas Ryan presents and try to implement them in your day to day development. Ryan also does an excellent job preparing for his shows and the delivery of the content is second to none on this list.
The Changelog Show (http://thechangelog.com/)
This is the latest podcast I've started to listen to. Wynn Netherland and Adam Stacoviak host this weekly show that focuses on Open Source projects and culture. Each week features an Open Source developer talking about their project and the open source landscape. This podcast does have a pretty Ruby-ish feel to it as both of the hosts are Ruby developers and most of the interviewees (at least through the episodes I've listened to but I still have about 12 to go before I'm current) have a Ruby background. Regardless I find this show informative and entertaining and I almost always find myself watching at least one project or developer on GitHub after the show.
News Based Podcasts
While learning new things is always one of the more important things a developer can do its also important to stay up on the current news and trends. While the following podcasts don't give you the amount of technical information as the ones I mentioned above these focus on keeping you up to date on their platforms of focus. While I downloaded every episode of the others the ones below I usually only download the latest shows so I can hear whats new and exciting.
The Java Possee (http://javaposse.com/) does a great job at keeping me up to date on what the Java community is doing (this podcast does also have a fair share of great technical information but It's just not on the level of the others). The JavaScript show (http://javascriptshow.com/) is a newer show which is brought to you by the same hosts as The Ruby Show (http://rubyshow.com/) and is formatted the exact same way where the hosts just go over a list of technology specific news and projects. Both of these do a superb job in giving you the latest and greatest news as well as point out projects that are doing exciting things. These shows are nice because they give you their content in a direct and concise format and leave it up to you to get further details.
For jQuery you can't go wrong with The Official jQuery Podcast (http://podcast.jquery.com/). I also wish I could speak intelligently on the yayQuery Podcast (http://yayquery.com/) becuase it seems like it will be full of excellent information as well. I do have episodes 0 - 22 queued up in my play list bug I just haven't gotten around to listening to them yet. Once I do I'll update this entry with more information.
While this list doesn't cover all of the podcasts I listen to regularly, it does cover the ones I tend to glean the most information from. Like I mentioned earlier, if there are others you know of that you think deserve mention in this post please leave me a comment and I'll give them a listen, and I'll try to keep this post up to date as I discover more good podcasts.
Monday, July 25, 2011
Monday, July 18, 2011
Mocking Java Objects In ColdFusion Unit Tests
I've been working on a project lately that has a few CFC's that rely heavily on a java object for much of their functionality. This was making my unit tests act more like functional tests since I was using the return values from the Java object to make my assertions. This didn't feel very good to me so I went to StackOverflow for some help. Edward Smith (Edward if you are reading this and would like me to link to something other than your stack overflow profile send me a comment and I'll update it) knocked it out of the park with his answer. I used what he said to implement the solution that this post is based off of. He mentioned that his company had used the Java mocking framework Mockito to mock Java objects in their ColdFusion unit tests. Brilliant! I already use Mockito for all of my Java unit tests, I just had never put it together that I could actually use it in my ColdFusion unit tests as well.
The first step in implementing this approach is to download the mockito jar file from http://www.mockito.org. For my implementation I'm using Mark Mandel's excellent JavaLoader project to create instances of java objects so I copy the jar into a lib folder in my application's root folder. Another approach would be to add the .jar file right to my ColdFusion server's instance, however I don't have any experience with this approach so I stuck with what I knew. This article on the Adobe blogs by Christian Cantrell might help you out if you'd rather use this approach.
Now that I have the .jar file in my project its time to make them available to my mxunit test. To do this I need to make them available to my test by loading them using JavaLoader and then to create an instance of the Mockto object so I can start mocking the Java objects. Its important to note that when using the JavaLoader approach you must also inititalize the .jar file of the object you mocking and ALL of the dependencies. Once the JavaLoader object is initialized with all of .jar files our objects need we need to create an instance of the mockito class for our test to use:
The next step is to create our mock Java objects. Since the component I'm trying to test is more or less a ColdFusion implementation of the java object I decided to recreate the mock before every test so I knew I was working with a clean copy of the mock. This means that I placed my mock code in my unit test's "setUp" method like so:
The syntax for creating a mock object in Mockito is pretty simple: variables.mockito.mock(variables.classLoader.create("com.sudios714.cfevernote.CFEvernote").init("123","S1","232","sandbox.evernote.com","mock").getClass()); Here I am calling the "mock" method on my Mockito object. The first parameter to the mock method is a Java class. In order to get a class I'm using the JavaLoader object's create method to create a new instance of a Java class and calling the getClass() method on that class to get the actual Java class to pass into Mockito. The last step is to inject it into my component. Now we have a working mock object injected into my component lets take a look at a test that puts my mock to use:
There are a few important things to note here. First is that the data that I'm creating for my mock is using a native Java object, in this case java.util.ArrayList. Since this is a part of the core Java language I don't need to use the JavaLoader to create an object for this data type. The next step is to do the actual mocking behavior. The statement variables.mockito.when(mockCFEvernote.listNotebooks(12)).thenReturn(retArray); is telling Mockito WHEN the listNotebooks method is called with a parameter of 12 to RETURN retArray which is the java.util.ArrayList object we created above.
Mockito can also be used to verify behavior, however this comes with a large caveat. Even if the verify statement is surrounded a try/catch statement (at least in my Win64/IIS7/CF9/Java 6 environment) if the verify statement fails, meaning that the method was not called with the expected parameter, the server will throw a 500 error. If the behavior verifies OK the test will run as expected. Knowing this if you'd still like to verify some behavior it can be accomplished by writing a verify statement like so: variables.mockito.verify(mockCFEvernote).listNotebooks(12); Here we are telling Mockito to verify that in the mockEvernote object the listNotebooks() method was called with a parameter of 12.
The first step in implementing this approach is to download the mockito jar file from http://www.mockito.org. For my implementation I'm using Mark Mandel's excellent JavaLoader project to create instances of java objects so I copy the jar into a lib folder in my application's root folder. Another approach would be to add the .jar file right to my ColdFusion server's instance, however I don't have any experience with this approach so I stuck with what I knew. This article on the Adobe blogs by Christian Cantrell might help you out if you'd rather use this approach.
Now that I have the .jar file in my project its time to make them available to my mxunit test. To do this I need to make them available to my test by loading them using JavaLoader and then to create an instance of the Mockto object so I can start mocking the Java objects. Its important to note that when using the JavaLoader approach you must also inititalize the .jar file of the object you mocking and ALL of the dependencies. Once the JavaLoader object is initialized with all of .jar files our objects need we need to create an instance of the mockito class for our test to use:
The next step is to create our mock Java objects. Since the component I'm trying to test is more or less a ColdFusion implementation of the java object I decided to recreate the mock before every test so I knew I was working with a clean copy of the mock. This means that I placed my mock code in my unit test's "setUp" method like so:
The syntax for creating a mock object in Mockito is pretty simple: variables.mockito.mock(variables.classLoader.create("com.sudios714.cfevernote.CFEvernote").init("123","S1","232","sandbox.evernote.com","mock").getClass()); Here I am calling the "mock" method on my Mockito object. The first parameter to the mock method is a Java class. In order to get a class I'm using the JavaLoader object's create method to create a new instance of a Java class and calling the getClass() method on that class to get the actual Java class to pass into Mockito. The last step is to inject it into my component. Now we have a working mock object injected into my component lets take a look at a test that puts my mock to use:
There are a few important things to note here. First is that the data that I'm creating for my mock is using a native Java object, in this case java.util.ArrayList. Since this is a part of the core Java language I don't need to use the JavaLoader to create an object for this data type. The next step is to do the actual mocking behavior. The statement variables.mockito.when(mockCFEvernote.listNotebooks(12)).thenReturn(retArray); is telling Mockito WHEN the listNotebooks method is called with a parameter of 12 to RETURN retArray which is the java.util.ArrayList object we created above.
Mockito can also be used to verify behavior, however this comes with a large caveat. Even if the verify statement is surrounded a try/catch statement (at least in my Win64/IIS7/CF9/Java 6 environment) if the verify statement fails, meaning that the method was not called with the expected parameter, the server will throw a 500 error. If the behavior verifies OK the test will run as expected. Knowing this if you'd still like to verify some behavior it can be accomplished by writing a verify statement like so: variables.mockito.verify(mockCFEvernote).listNotebooks(12); Here we are telling Mockito to verify that in the mockEvernote object the listNotebooks() method was called with a parameter of 12.
Labels:
ColdFusion,
Mockito,
MXUnit,
Unit Testing
Subscribe to:
Posts (Atom)