Skip to content

JUnit 4 at Java Polis


At Java Polis I made a quicky (a presentation of 15 minutes) about JUnit 4. I've been using JUnit for quite a while. I've also tried TestNG but never really got into it. In summer 2006 I worked with JUnit 4 at a customer. I've used it quite intensively, that's when I decided to write an article about it (Get Acquainted with the New Advanced Features of JUnit 4). I've proposed a quicky to JavaPolis and it was accepted. Checkout the blog I wrote about it.

If you are interested in this presentation just check the slides.

Read More →

JavaPolis 2006 – Leaving tomorow morning

God, I‘m so involved in finishing writing my book that I’ve completly forgotten talking about JavaPolis. I’m leaving tomorow from Paris in an early train (6:55am) and will present a Quicky about JUnit 4 on Thursday. I‘ve already picked up the sessions I want to attend, mainly JEE, Scripting languages and a bit of JSE. A couple of former BEA colleagues should be there and a few french open source actors too. Hope I will have enough time to attend all the sessions I want and have a couple of beers with them.

Read More →

Writing a book about Java EE 5

A couple of days ago a friend sent me an email saying that I haven‘t blogged for few weeks now. The reason is that I‘m writing a book about Java EE 5 and it‘s taking me a lot of time (after work and in the week-ends). The chapters will roughtly be : * Presentation of Java EE 5 * Presentation of the Architecture of the application to develop * Java Persistent API * Stateless EJB 3.0 * JNDI an remote access with swing client * JSF 1.2 and JSP 2.1 (Unified EL) * Stateful EJB * JMS and MDB * Web Services (with Jaxb 2) It‘s a practical book, not a reference one, so there is only 30/40 pages per chapter with external references to go to. It‘s aimed at experienced java developpers who have had web development experience. I am a JBoss/Hibernate user but unfortunately I had to leave these frameworks because not really Java EE 5 compliant (stil JSP 2 and JSF 1.1). I‘m using Glassfish with Toplink and Derby. I lost a bit of time with this switch but it‘s ok. I didn‘t know Glassfish before and I‘m quite impressed with what they‘ve done. Ok, have to go and I will blog more about what I‘m doing… I should publish an article about Java EE 5. PS : JSF is driving me mad

Read More →

How to unit test CRUD operations

I like to unit test CRUD (Create, Read, Update, Delete) operations for my domain objects as well as find all. I use the same template again and again, it’s quick to do and makes sure that the basic operations work. Here is what I do : * A first find all to get all the objects from the database * Create an object with random values and persist it into the database * Find the created object from the database * Make sure it exists * Make sure it has the right random values * Update the created object with other random values into the database * Find the updated object from the database * Make sure it still exists * Make sure it has the new random values * A second find all makes sure that there is one more object in the database * Delete the object from the database * Find the object from the database * Make sure it doesn’t exist * A third find all makes sure that there is the initial number of objects in the database Here is the (simplified) JUnit code that tests the CRUD operations for an Item. @Test public void testCRUD() throws Exception { // Gets two random numbers Long random = getRandom(); Long updateRandom = getRandom(); // Item is the domain object Item item = new Item(); // The method findAll brings back all the objects from the DB […]

Read More →

HelloWorld with JPA, Hibernate and MySql

I love Hello Worlds. So when I read the blog HelloWorld with JPA, TopLink and MySql I’ve quickly copied/pasted the code, downloaded everyhting and made it work. Good. But because I’m more a Hibernate user, I thought, let’s give it a try with the same example but using Hibernate EntityManager instead of Toplink. So here is the same simple example of standalone java application using Java Persistence API (JPA), Hibernate, and MySql 5. Here is what you have to do : * First, download Hibernate Core 3.2.CR2, Hibernate Annotations 3.2.0 CR1 and Hibernate EntityManager 3.2.0 CR1 * Write the META-INF/persistence.xml file <persistence> <persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL"> <class>com.foo.Greeting</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="create"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> </properties> </persistence-unit> </persistence> * Use the same Entity class and Main class than the one written in the HelloWorld with JPA, TopLink and MySql blog * Start MySQL * Compile and run the project with the folowing classpath java cp ..\classes;%LIB%\ejb3-persistence.jar; %LIB%\hibernate-entitymanager.jar;%LIB%\hibernate3.jar;%LIB%\jboss-common.jar; %LIB%\dom4j-1.6.1.jar;%LIB%\hibernate-annotations.jar;%LIB%\commons-logging-1.0.4.jar; %LIB%\cglib-2.1.3.jar;%LIB%\javassist.jar;%LIB%\commons-collections-2.1.1.jar; %LIB%\mysql-connector-java-5.0.3-bin.jar;%LIB%\ehcache-1.2.jar;%LIB%\asm.jar; %LIB%\jta.jar com.foo.HelloWorld

Read More →

Article on JUnit 4

I’ve published an article about JUnit 4 on DevX : Get Acquainted with the New Advanced Features of JUnit 4. JUnit 4 has changed a lot and it looks like there is much more to come. This article shows you how to migrate from JUnit 3.8 to JUnit 4 and gives you an overview of JUnit 4 new features. An article is never written alone. So first of all I would like to thank my wife Denise who read and corrected a boring technical article that she didn’t understand a word. Second, Lori Piquet from JupiterMedia for his help and expertise in writing articles. And a special thanks to both my friends Alexis Midon and Zouheir Cadi who took a bit of time to review this article. Do not hesitate to post comments.

Read More →