here is a tutorial I wrote for the junit sampler

http://svn.apache.org/repos/asf/jakarta/jmeter/trunk/xdocs/usermanual/junitsampler_tutorial.pdf

basically, to use oneTimeSetup, you have to create a threadgroup and place
all your oneTimeSetUp calls in that thread group. the threadGroup should be
at the top and only run once with 1 thread. Then the actual test methods
should be placed in a separate thread group.

when you select "oneTimeSetUp" as the test method, you have to make sure to
check "do not call setUp". Since JMeter is a multi-threaded environment,
it's necessary to place oneTimeSetUp/oneTimeTearDown in a threadgroup with 1
thread and 1 iteration.


hope that helps

peter

On 11/11/05, Krishnasankar R <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'd like to know how to use the onetimesetup method in the JUnit sampler.
> When I tried, the data that was set up in oneTimeSetUp is not visible in
> the
> test methods.
>
> Please see the JUnit testcase code below where the variable oneTimeValue
> is
> being set in the oneTimeSetUp method. Its value is not visible in the test
> method. In the JMX, there's a single thread group to which two JUnit
> samplers are attached. The first sampler uses the oneTimeSetUp, does not
> call setup and teardown. The second sampler calls the actual test method.
>
> For the example, pl add WebLogic.jar or the client jars (WebLogic v8.1.4)
> and the jars and the following to user.classpath in jmeter.bat:
>
> <bea-home>/user_projects/domains/yourdomain/applications/ejb20_basic_statele
> ssSession.jar
>
> Your help would be greatly appreciated.
>
> Thanks,
> Krishna
>
> Code:
>
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
>
> import java.util.Properties;
> import java.rmi.RemoteException;
>
> import javax.naming.*;
> import javax.rmi.PortableRemoteObject;
>
> import examples.ejb20.basic.statelessSession.*;
>
> public class TraderTestClient extends TestCase {
>
> private static final String REMOTE_REFERENCE_IS_NULL
> = "Remote interface reference is null";
> private static final String JNDI_NAME =
> "ejb20-statelessSession-TraderHome";
> private Trader trader;
> private TraderHome traderHome;
> private int oneTimeValue;
>
> public TraderTestClient() {
> super();
> }
>
> public TraderTestClient(String name) {
> super(name);
> }
>
> public void initialize() {
> try {
> //get naming context
> Context context = getInitialContext();
>
> //look up jndi name
> Object ref = context.lookup(JNDI_NAME);
>
> System.out.println("ref: " +
> ref.getClass().getName());
>
> //look up jndi name and cast to Home interface
> traderHome = (TraderHome)
> PortableRemoteObject.narrow(ref, TraderHome.class);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> }
>
> public Context getInitialContext() {
> InitialContext initialContext = null;
> try {
> String url = "t3://localhost:7001";
> Properties properties = new Properties();
> properties.put(Context.INITIAL_CONTEXT_FACTORY,
>
> "weblogic.jndi.WLInitialContextFactory");
> properties.put(Context.PROVIDER_URL, url);
> initialContext = new InitialContext(properties);
> } catch (Exception e) {
> e.printStackTrace();
> }
> return initialContext;
> }
>
> public void setUp() {
> System.out.println("In setUp()");
> initialize();
> create();
> }
>
> public void tearDown() {
> System.out.println("In tearDown()");
> traderHome = null;
> trader = null;
> }
>
> public void oneTimeSetUp() {
> System.out.println("oneTimeSetUp called -- ");
> oneTimeValue=5;
> System.out.println("oneTimeValue: " + oneTimeValue);
> }
>
> public void oneTimeTearDown() {
> System.out.println("oneTimeTearDown called -- ");
> }
>
> public void create() {
> try {
> trader = (Trader) PortableRemoteObject.narrow
>
> (traderHome.create(), Trader.class);
> } catch (Exception e) {
> e.printStackTrace();
> }
> assertNotNull("Unable to create Trader", trader);
> }
>
> /**
> * Invoke a method on the Trader bean
> */
> public void testTraderBuy() {
> // buy specified # of shares of a company
> System.out.println("buy specified # of shares of a
> company");
> System.out.println("oneTimeValue: " + oneTimeValue);
> TradeResult tradeResult = null;
> try {
> tradeResult = trader.buy("Scandent Solutions",
> 1000);
> } catch (RemoteException re) {
> re.printStackTrace();
> }
> assertNotNull("Number of stocks bought: ", tradeResult);
> assertTrue("Number of stocks bought: ",
> tradeResult.getNumberTraded()!=0);
> assertNotNull("Stock symbol: ",
> tradeResult.getStockSymbol());
> }
>
> public static void main(String[] args) throws Exception {
> junit.textui.TestRunner.run(TraderTestClient.class);
> }
>
> } // class
>
>
> ****************************************************************************
> This communication contains information, which is confidential and may
> also
> be privileged. It is for the exclusive use of the intended recipient(s).
> If
> you are not the intended recipient(s), please note that any distribution,
> printing, copying or use of this communication or the information in it is
> strictly prohibited. If you have received this communication in error,
> please notify the sender immediately and then destroy any copies of it.
>
> ****************************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to