Archive for May, 2007

Test More for Java?!

Any one know, does there exist a TestSimple/More (from Perl) for Java like the module for Perl?

whats that you say? I wrote about TestMore in Perl and PHP Here and here also!

I did a quick scan with google didn't give me much hope. So I wrote this quickly on the train this morning, since I can't hardly stand to program in any language without a TestMore like implementation.. (I know there's JUnit, and I'ved used it before, but its alot of overhead.. I just needed some quick tests!)

Class: (not making any claim this is the best or greatest way, and not 100% TAP protocol)

JAVA:
  1. package com.myawesomesite.util;
  2.  
  3. public class TestSimple {
  4.  
  5.  private int testCount;
  6.  
  7.  public TestSimple() {
  8.   this.testCount = 0;
  9.  }
  10.  
  11.  public void ok(boolean truth, String message) {
  12.   this.testCount++;
  13.   System.out.println( (truth ? "ok " : "not ok ")
  14.                       + this.testCount + " - "
  15.                       + message);
  16.  }

Usage:

JAVA:
  1. package com.myawesomesite.java;
  2.  
  3. import com.myawesomesite.java.*;
  4. import com.myawesomesite.util.TestSimple;
  5.  
  6. public class TestAnimal {
  7.  
  8.  public static void main(String[] args) {
  9.   TestSimple test = new TestSimple();
  10.  
  11.   Dog bob = new Dog();
  12.  
  13.   bob.setColor("green");
  14.   bob.setCollarSize(10);
  15.  
  16.   test.ok(bob.getColor() == "green", "bob's color is green");
  17.   test.ok(bob.getCollarSize() == 10,"bob's collar size is 10");
  18.   test.ok(bob.getCollarSize() == 0,"bob's collar size 0");
  19.  
  20.  
  21.  }
  22.  
  23. }

output is:

ok 1 - bob's color is green
ok 2 - bob's collar size is 10
not ok 3 - bob's collar size is 0

Comments

Book Review: Beginning Ruby On Rails E-Commerce

Beginning Ruby On Rails E-Commerce
From Novice to Professional
by Christian Hellsten and Jarkko Laine
published by: Apress

Book Site | Sample Chapter | Table of Contents

I got this book to review and set it on the shelf for a few months... by the time I got to it Rails was up til version 1.2 and this seems to be written for version 1.1.2 – DOH! I tried a few examples and wasn't compiling. After a little investigation there are only a few differences that would hinder this book from working with Rails 1.2. Namely, the assert_select has replaced assert_tag. That being said, this book is still great and applicable to Rails today. If you think about it, with as fast as Rails as grown it is impossible to keep 100% up to date!

This book is totally fantastic for beginners – because it actually shows Test Driven Development. What you say? Most books say something like that “to keep code size down, tests and error checking have been left for an exercise to the reader” ... Riiiiiiiiiiight. How are you going to teach people coding that way? Tests should just be an automatic task of a programmer. Write some test... write some code. I honestly can't imagine anymore how you could code anyways without them!

Not only does this book cover testing (including acceptance testing with selenium in later chapters – whoo hoo!) it starts out with not using scaffolding. I think, and this happened to me, at first I used scaffolding for everything and didn't really understand the process. The book first goes through the “scaffold process” by hand, writing each method and view – after writing the test. Very cool. Then it tells you how to use scaffolding for the next model in the sample application. Awesome.

It talks about common concepts for really any site – tagging, adding forum, adding a form to upload images, browsing a list of products, multiple language support. Even if you are not selling anything on your site, you will still find this book extremely helpful.

Impress your friends! Learn how to write a DSL for testing. This is cool stuff, DSLs fascinate me to no end. Any and all mentions of it I study intently. Rails is in a way, a DSL for web applications!

Being true to the title “e-commerce” it actually talks about how to do payments over the web. Most books who talk about shopping carts skip that important step!

When you are ready to make your millions on the web there is quite an extensive chapter on deploying your site. It talks about LightTPD, capastrano, caching, and security! Its really nice to have all this in a book, instead of constantly looking online for documentation

My only complaint is – it doesn't specifically mention what version of rails it used, I assume from the output of script/about that is 1.1.2 ... and they should of talked about how to check out a particular version of Rails, just in case you wanted to use the exact version that is used in the book. Which may not be a bad idea for new users.

Comments

Java… Java…

In college, about 7 years ago (yikes) I learned Java near the end of my year. I loved it. I got an A in the class and was all set to get a java job after college. Uhh.. how AM I supposed to get 3 years experience?!?! ... so thats when I picked up PHP and went down the web programming path..

At my current job, a Perl job, they have a study group for the Java certification. I thought I'd join them, taking every advantage for learning that I can. I am not 100% sure I will take the test, but it will motivate me I think to get back into Java. I joke with my Java programmer friends "I need to relearn java, so I can convert all your java apps to ruby someday.. haha" .. I don't even know if i will like doing Java.

My husband made me throw out 80% of my computer books that were out of date! "GASP! what? throw out DOS for Dummies!?!?! VB 5????" ... I threw out some java books. A friend of mine said they although java has some new features in the past years the core library is probably still about the same. But really I don't have time to waste with old books, so I decided if I should EVER want to do Java.. I'll get some new ones.

I was looking over the books in the java category at bookpool - there are so many! Does anybody have any suggestions? I think I have a pretty firm grasp on objects, interfaces, etc all that stuff. I just need a reference book or something to get me re-familiarized with the language and learn some of the java idioms and conventions.

Comments

Get Er DONE!

Well -- anyone who knows me know that I love ruby... and perl next, and PHP comes in last of my favorite development languages. So of course when mom needed a website for her Bakery, I was going to do it in Ruby! I spent time getting my environment setup... threw it in subversion... setup a staging area on my server.. got some verbage, some photos and then finaly ready to hammer out the code.

I needed about 10 or so pages and an image gallery that would be easy to post photos to. I did a site a few years ago with Rails and file_column plugin and it was fantastic. I did it in 2 days and it was wonderful.

I am not quite sure what the problem was but I couldn't get file_column to work for nothing! .. so I tried acts_as_attachment... no luck there either. i was using rails 1.2.2 on live and staging... i searched and searched on the errors I was having and no luck! PHOOOOOOOOEEEEYY! I decided to just use Dreamweaver Templates (which actually are quite nice for small sites if you want to avoid programming) and make a static site... to get at least SOMETHING UP!

I decided to use PHP's Gallery to store photos, at least for the admin side. I had used it before and it has a fantastic java app called Gallery Remote that you run on your PC to upload photos. That's easy. Then for some reason I thought - hey wonder whats up with Drupal? I went ... I looked... hmm. So I downloaded it to my localhost and installed. Very nice! So I put it up on my moms site and configured it, added a module to connect to gallery -- and within 2 days I was done. Sure I needed a few more little things, but that was way more then I could ever hope to accomplish with my homegrown site in rails.

So rails, I'm a little miffed at you. i wonder, are there too many cooks in the kitchen? are you getting kinda too big too fast? or am I just lazy and didn't want to write a file upload, image resizing code myself? I didn't use scaffolding for some parts and did TDD as I went along! I dunno...

I've always liked the Gallery codebase, its fantastic and Drupal as well. I've used and developed custom code for both. With good codebases, PHP doesn't seem so bad. I might actually see if I can contribute to those projects.

I'm not saying that Rails == Drupal ... using Rails would have certainly been more coding on my part, but the end result is about the same. What I wanted to do with Rails, Drupal had most of it done for me.

BTW, if you want to see the bakery site, check it out. We have a new logo and color scheme in the works!

Comments