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.
Have you see the developerWorks article on using JUnit with Commerce?
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
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
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/
Thanks for the tips!! I will certanily check out the cactus project and
try unit testing this weekend..
Regards.
Sabrang