Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using JUnit to unit test Commerce commands..

560 views
Skip to first unread message

sab...@gmail.com

unread,
Jan 28, 2006, 5:10:37 PM1/28/06
to
Guys,

I wanted advice on using JUnit for testing commerce commands, I am just
starting out with JUnit..

I was playing around with that and found that writing the unit tests
could be a cumbersome task for WCS. For regular Java client apps it
seems fairly straightforward.

Am I missing something very basic here? Any advice or sample will be
highly appreciated.

Looking forward to hearing your suggestions, thanks in advance..

Sabrang.

Rhett

unread,
Jan 30, 2006, 10:24:03 AM1/30/06
to
Hello Sabrang,

Have you see the developerWorks article on using JUnit with Commerce?

http://www-128.ibm.com/developerworks/websphere/library/techarticles/0601_vandergoot/0601_vandergoot.html

Also, another good bookmark that all of us WC veterans have is the WC
Zone:

http://www-128.ibm.com/developerworks/websphere/zones/commerce/

Hope this helps,

-Rhett

sab...@gmail.com

unread,
Feb 1, 2006, 12:34:01 PM2/1/06
to
Rhett,

Thanks for your response!

But in that example they are testing a regular Java class. If I want to
unit test say my custom implementation of OrderItemAdd, I will have to
build command context and all sorts of info. before I can unit test it
right? Can you shed some light on how would you go about unit testing a
command like that?

Eagerly awaiting your reply.

Sabrang

Ian Maurer

unread,
Feb 2, 2006, 8:41:31 AM2/2/06
to
Sabrang,

Yes, you will need to create a context and pass it to your command
using the setCommandContent method before calling execute. Below is an
example of creating a content, command, and executing it. Also, by
using the command factory to create your instance, you can verify that
your command registration is working correctly.

import com.ibm.commerce.command.CommandContextImpl;
import com.ibm.commerce.command.CommandFactory;

...

// Create Command Context
CommandContextImpl context = new CommandContextImpl();
context.setStoreId(TestConstants.storeId);
context.setUserId(TestConstants.adminId);
logger.debug("Command Context Created.");


// Create and Execute Command
OrderItemAddCmd cmd =
CommandFactory.createCommand(OrderItemAddCmd.NAME,
TestConstants.storeId);
cmd.setCommandContext(context);
cmd.performExecute();

Also, you might want to look at Cactus instead of JUnitEE (as suggested
by the article). I think both projects are very similar but I was able
to find many more online resources about Cactus. Here are some links to
start you off, if you are interested:

http://jakarta.apache.org/cactus/
http://www-128.ibm.com/developerworks/websphere/techjournal/0206_wosnick/wosnick.html?open&l=937,t=gr

Good Luck,
Ian Maurer
http://itmaurer.com/

sab...@gmail.com

unread,
Feb 2, 2006, 9:29:38 AM2/2/06
to
Ian,

Thanks for the tips!! I will certanily check out the cactus project and
try unit testing this weekend..

Regards.

Sabrang

0 new messages