How to mock NSURLConnection.sendAsynchronousRequest in unit testing?

What tips do you have to add unit testing to an EJB/Websphere Commerce project?

  • I'm working for a consultancy that uses WebSphere Commerce. In other roles I have had to unit testing everything but relied on Spring's separation of concerns, and I have been easily able to bounce refactoring ideas off of peers. What are some coding structures I can look at so I can add in unit testing? We're using Commerce 7.0 (7.0.0.6)

  • Answer:

    The NVP commands have no specific testing functionality but you can use Cactus. The BOD commands have an specific Junit project you can use for that purpose. In Commerce 7 it is recommended to use Selenium. http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.starterstores.doc%2Ftasks%2Ftsminstallharnessinrad.htm

Raul Lapeira at Quora Visit the source

Was this solution helpful to you?

Other answers

First, let me apologise for the part I played in WebSphere Commerce. I started working on it when it was still Net.Commerce in 1997. I left it in 2001. I'm going to guess that this advice still helps. (By the way, when I wrote JUnit Recipes, the EJB chapter includes all the advice you'll ever need, and you can extend the ideas to any framework.) Rule 1: don't put non-framework-using code directly into the framework extensions. Rule 2: first learn rule 1. For EJBs--I'll go with EJB 2-style session beans, but the advice remains the same for all EJBs (except CMP Entity Beans, but nobody really does that, right?)--you'll probably start writing code directly into your SessionBean class. Don't. Any code that doesn't have to know that there's an EJB around should move into a new class X so that the EJB exposes X's behavior to the EJB container. Example: if your Session Bean uses JNDI to look up a service, then leave the looking-up code in the Session Bean. Once you have that service through its Service Interface, pass that instance to X, which has no idea where the Service Interface came from. The Session Bean's job is to look up the service, then ask X to work on it. X doesn't know anything about EJB. You can run (and therefore test) in a plain Java VM. THAT'S THE POINT. Any code that can reasonably move from the Session Bean into X, where it can run with no longer (at all!) of the EJB container... do it. You can test X at will with plain Java/JUnit/TestNG/whatever, and save Cactus (and its friends) for the parts of the Session Bean that you're unsure of that absolutely need the EJB container to run. Your Session Bean (or EJB extension point, in general) should be relatively thin and do only infrastructure processing (like JNDI lookups or rolling back transactions), leaving business logic (calculations, policies, anything that would have to happen even without EJBs) to Plain Old Java Classes. Of course, it's really like War Games: the only winning move is not to play. Good luck.

J. B. Rainsberger

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.