Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How do I call another test within a test?
How do I call another test within a test? [message #495454] Wed, 04 November 2009 22:59 Go to next message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
I'm fairly new to SWTBot. I have written several scripts to test our RCP plug-in application. I would like to be able to call the same set-up script from within all the other test scripts. Right now all my scripts have the same set-up methods built into them.

I have tried using the "extends" specification but that calls the set-up script after the test runs, which of course then fails. I need it to run 1st. Could someone please give me some sample code on how to get this to work??

Thanks,

Michelle
Re: How do I call another test within a test? [message #495623 is a reply to message #495454] Thu, 05 November 2009 14:24 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
M. K. wrote:
> I'm fairly new to SWTBot. I have written several scripts to test our
> RCP plug-in application. I would like to be able to call the same
> set-up script from within all the other test scripts. Right now all my
> scripts have the same set-up methods built into them.
>
> I have tried using the "extends" specification but that calls the set-up
> script after the test runs, which of course then fails. I need it to
> run 1st. Could someone please give me some sample code on how to get
> this to work??
>
> Thanks,
>
> Michelle

I'm not really if I understand what you are trying to accomplish, but
here's a shot (using JUnit 3):

if you have two tests classes with this setUp method:
public class TestClass1 extends SWTBotTestCase
{
protected void setUp() throws Exception
{
bot.text().setText("foo");
}

public void testSomething()
{
//do something
}
}

public class TestClass2 extends SWTBotTestCase
{
protected void setUp() throws Exception
{
bot.text().setText("foo");
}

public void testSomethingElse()
{
//do something else
}
}

Solution 1: you can merge those two classes together
public class TestClass extends SWTBotTestCase
{
protected void setUp() throws Exception
{
bot.text().setText("foo");
}

public void testSomethingElse()
{
//do something else
}

public void testSomething()
{
//do something
}
}

This way, the setUp method will be executed before each test
Remarks: this solution might not be desirable if the two tests classes
test something completely different.

Solution 2: extract the setUp method in an Helper class and call the new
method within your test class:
public final class TestHelper
{
private TestHelper()
{
// forbid instanciation
}

public void commonSetUp(SWTBot bot) //Could also be a
SWTWorkbenchBot if required
{
bot.text().setText("foo");
}
}

public class TestClass2 extends SWTBotTestCase
{
protected void setUp() throws Exception
{
TestHelper.commonSetUp(bot);
}

public void testSomethingElse()
{
//do something else
}
}

Solution 3: probably the closest to what I understand you want to do,
extract the setUp method in a superclass and make your two test classes
inherit from it:
public abstract SuperTestClass extends SWTBotTestCase
{
protected void setUp() throws Exception
{
bot.text().setText("foo");
}
}

public class TestClass1 extends SuperTestClass
{
public void testSomething()
{
//do something
}
}

public class TestClass2 extends SuperTestClass
{
public void testSomethingElse()
{
//do something else
}
}

Hope this helps
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: How do I call another test within a test? [message #495649 is a reply to message #495623] Thu, 05 November 2009 15:54 Go to previous messageGo to next message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
I'm QA not a Java programmer, so please bear with me. I tried your 3rd suggestion and get syntax errors. So I'll try to better explain what I'm attempting to do.

I have a stand-alone set-up class that contains static string variables, settings, and preference methods. I want to be able to call this one class from within all my other test classes. These are all in the same package.

My set-up class starts like this: public class SetupTest {

My test classes start like this:

public class EditMember extends SetupTest {

When I run EditMember, it's methods are executed before the SetupTest methods. The test fails because the various settings and variables that were needed by EditMember were not set yet.

How do I code this so SetupTest is executed first?
Re: How do I call another test within a test? [message #495665 is a reply to message #495649] Thu, 05 November 2009 17:02 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
M. K. wrote:
> My set-up class starts like this: public class SetupTest {
>
> My test classes start like this:
> public class EditMember extends SetupTest {
>
> When I run EditMember, it's methods are executed before the SetupTest
> methods. The test fails because the various settings and variables that
> were needed by EditMember were not set yet.
> How do I code this so SetupTest is executed first?

Oooooo, ok then!

I guess the methods in SetupTest are all coded as test methods with the
Junit scheme:
testTestName (JUnit 3) or annotated with @Test (JUnit 4)
like so:
public class SetupTest {
public void testSetUp1() {
// SetUp something
}

public void testSetUp2() {
// SetUp something else
}
}

or JUnit 4

public class SetupTest {
@Test
public void setUp1() {
// SetUp something
}

@Test
public void setUp2() {
// SetUp something else
}
}

instead, you should probably do the following
JUnit3:
public class SetupTest {
public void setUp() {
setUp1();
setUp2();
}

public void setUp1() {
// SetUp something
}

public void setUp2() {
// SetUp something else
}
}

JUnit4:
public class SetupTest {
@Before
public void setUp1() {
// SetUp something
}

@Before
public void setUp2() {
// SetUp something else
}
}

The setUp() method in JUnit3 is executed before any test methods. Same
goes for the methods annotated with @Before in JUnit4. Then, in your
EditMember class, if you have a setUp() or @Before method, it will be
executed after SetupTest's method, but before your test methods.

Another thing I should mention about JUnit4: there is usually no
guarantee of the order the methods will be run. I you want an explicit
order, do only one @Before method and call all the others within it:
@Before
public void setUpMethod(){
setUp1();
setUp2();
}


Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: How do I call another test within a test? [message #495696 is a reply to message #495454] Thu, 05 November 2009 19:10 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
class MyTest1{
MySetup setup;
@Before public void beforeTest(){
this.setup = new MySetup();
this.setup.setup();

}

@After public void afterTest(){
this.setup.cleanup();
}

@Test public void someTest{}

}

the common setup and teardown can be pushed into the methods in
CommonSetup which may be shared by as many classes as you wish.

-- Ketan

M. K. wrote:
> I'm fairly new to SWTBot. I have written several scripts to test our
> RCP plug-in application. I would like to be able to call the same
> set-up script from within all the other test scripts. Right now all my
> scripts have the same set-up methods built into them.
>
> I have tried using the "extends" specification but that calls the set-up
> script after the test runs, which of course then fails. I need it to
> run 1st. Could someone please give me some sample code on how to get
> this to work??
>
> Thanks,
>
> Michelle
Re: How do I call another test within a test? [message #495754 is a reply to message #495696] Thu, 05 November 2009 22:06 Go to previous messageGo to next message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
Neither suggestion worked. When I run my EditMember class, in my JUnit view it lists only the methods from EditMember and I get these errors:

java.lang.NullPointerException
at myPackage.SetupTest.OpenView3(SetupTest.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner. run(SWTBotJunit4ClassRunner.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:117)
at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:71)
at java.lang.Thread.run(Thread.java:619)


OpenView3 is the last method in the SetupTest class. SetupTest runs just fine by itself, so I know its syntax is ok.

When I change all my methods in SetupTest back to @Test and use "extends" on my EditMember class It shows the SetupTest methods as having been run in the JUnit view, but I get this exception.

java.lang.NullPointerException
at myPackage.EditMember.CreateDatasetMask(EditMember.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner. run(SWTBotJunit4ClassRunner.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:64)
at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:117)
at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:71)
at java.lang.Thread.run(Thread.java:619)

The CreateDatasetMask is the 1st method in EditMember. So now what?

[Updated on: Thu, 05 November 2009 22:07]

Report message to a moderator

Re: How do I call another test within a test? [message #495781 is a reply to message #495754] Fri, 06 November 2009 03:24 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
I would recommend using the junit4 style of writing tests. Junit 3.x is
old, and has more likelihood of being dropped in future releases.

Looking at both the stack traces the NPE is because your test code
invokes something on an object that is not initialized. This hints
there's something wrong with the method; someone could probably help
better if you show us some code :)

-- Ketan

M. K. wrote:
> ither suggestion worked. When I run my EditMember class, in my JUnit
> view it lists only the methods from EditMember and I get these errors:
>
> java.lang.NullPointerException
> at myPackage.SetupTest.OpenView3(SetupTest.java:69)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
> ssorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
> thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> ectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> ameworkMethod.java:41)
> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
> nBefores.java:27)
> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
> Afters.java:31)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:73)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:46)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
> nBefores.java:28)
> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
> Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.
> run(SWTBotJunit4ClassRunner.java:54)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> un(JUnit4TestReference.java:46)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
> Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> emoteTestRunner.java:390)
> at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(
> RemotePluginTestRunner.java:64)
> at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U
> ITestApplication.java:117)
> at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work
> benchTestable.java:71)
> at java.lang.Thread.run(Thread.java:619)
>
>
> OpenView3 is the last method in the SetupTest class. SetupTest runs
> just fine by itself, so I know its syntax is ok.
>
> When I change all my methods in SetupTest back to @Test and use
> "extends" on my EditMember class It shows the SetupTest methods as
> having been run in the JUnit view, but I get this exception.
> java.lang.NullPointerException
> at myPackage.EditMember.CreateDatasetMask(EditMember.java:27)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
> ssorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
> thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> ectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> ameworkMethod.java:41)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(
> InvokeMethod.java:20)
> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
> nBefores.java:28)
> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
> Afters.java:31)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:73)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:46)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
> nBefores.java:28)
> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
> Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.
> run(SWTBotJunit4ClassRunner.java:54)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> un(JUnit4TestReference.java:46)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
> Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> emoteTestRunner.java:390)
> at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(
> RemotePluginTestRunner.java:64)
> at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U
> ITestApplication.java:117)
> at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work
> benchTestable.java:71)
> at java.lang.Thread.run(Thread.java:619)
>
> The CreateDatasetMask is the 1st method in EditMember. So now what?
Re: How do I call another test within a test? [message #495782 is a reply to message #495781] Fri, 06 November 2009 03:28 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
I'd like to add that there are some tests used by swtbot available in
the repo[1] if you'd like to see examples. The editor test[2]
particularly has a setup method that you may like to look at.


[1] -
http://github.com/ketan/swtbot/tree/master/org.eclipse.swtbo t.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/ widgets/
[2] -
http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbo t.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/ widgets/SWTBotEclipseEditorTest.java


-- Ketan


Ketan Padegaonkar wrote:
> I would recommend using the junit4 style of writing tests. Junit 3.x is
> old, and has more likelihood of being dropped in future releases.
>
> Looking at both the stack traces the NPE is because your test code
> invokes something on an object that is not initialized. This hints
> there's something wrong with the method; someone could probably help
> better if you show us some code :)
>
> -- Ketan
>
> M. K. wrote:
>> ither suggestion worked. When I run my EditMember class, in my JUnit
>> view it lists only the methods from EditMember and I get these errors:
>>
>> java.lang.NullPointerException
>> at myPackage.SetupTest.OpenView3(SetupTest.java:69)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
>> ssorImpl.java:39)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
>> thodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
>> FrameworkMethod.java:44)
>> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
>> ectiveCallable.java:15)
>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
>> ameworkMethod.java:41)
>> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
>> nBefores.java:27)
>> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
>> Afters.java:31)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
>> 4ClassRunner.java:73)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
>> 4ClassRunner.java:46)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java
>> :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
>> nBefores.java:28)
>> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
>> Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.
>> run(SWTBotJunit4ClassRunner.java:54)
>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
>> un(JUnit4TestReference.java:46)
>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
>> Execution.java:38)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
>> sts(RemoteTestRunner.java:467)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
>> sts(RemoteTestRunner.java:683)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
>> emoteTestRunner.java:390)
>> at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(
>> RemotePluginTestRunner.java:64)
>> at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U
>> ITestApplication.java:117)
>> at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work
>> benchTestable.java:71)
>> at java.lang.Thread.run(Thread.java:619)
>>
>>
>> OpenView3 is the last method in the SetupTest class. SetupTest runs
>> just fine by itself, so I know its syntax is ok.
>>
>> When I change all my methods in SetupTest back to @Test and use
>> "extends" on my EditMember class It shows the SetupTest methods as
>> having been run in the JUnit view, but I get this exception.
>> java.lang.NullPointerException
>> at myPackage.EditMember.CreateDatasetMask(EditMember.java:27)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
>> ssorImpl.java:39)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
>> thodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
>> FrameworkMethod.java:44)
>> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
>> ectiveCallable.java:15)
>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
>> ameworkMethod.java:41)
>> at org.junit.internal.runners.statements.InvokeMethod.evaluate(
>> InvokeMethod.java:20)
>> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
>> nBefores.java:28)
>> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
>> Afters.java:31)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
>> 4ClassRunner.java:73)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
>> 4ClassRunner.java:46)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java
>> :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at org.junit.internal.runners.statements.RunBefores.evaluate(Ru
>> nBefores.java:28)
>> at org.junit.internal.runners.statements.RunAfters.evaluate(Run
>> Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.
>> run(SWTBotJunit4ClassRunner.java:54)
>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
>> un(JUnit4TestReference.java:46)
>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
>> Execution.java:38)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
>> sts(RemoteTestRunner.java:467)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
>> sts(RemoteTestRunner.java:683)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
>> emoteTestRunner.java:390)
>> at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(
>> RemotePluginTestRunner.java:64)
>> at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U
>> ITestApplication.java:117)
>> at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work
>> benchTestable.java:71)
>> at java.lang.Thread.run(Thread.java:619)
>>
>> The CreateDatasetMask is the 1st method in EditMember. So now what?
Re: How do I call another test within a test? [message #496599 is a reply to message #495782] Tue, 10 November 2009 16:36 Go to previous message
M. K. is currently offline M. K.Friend
Messages: 9
Registered: September 2009
Junior Member
Hello,

1st off I'd like to point out I am using JUint4 to write my test scripts. I finally figured out how to get this going by combining the suggestions.

My SetupTest class looks like this:

public class SetupTest {
private static SWTWorkbenchBot bot;

static String connection = "connection";
static String lanid = "lanid";
static String password = "******";

@BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTWorkbenchBot();
bot.viewByTitle("Welcome").close();
OpenPersp();
EditorPref();
OpenView();
Logon();
}

private static void OpenPersp() throws Exception {
statements;
}

private static void EditorPref() throws Exception {
statements;
}

Etc.

A test that calls my SetupTest starts like this:

public class EditMember extends SetupTest {
private static SWTWorkbenchBot bot;

@Test
public void CreateDatasetMask() throws Exception {
bot = new SWTWorkbenchBot();
statements
}

@Test
Etc.

I am able to use the static variables within the EditMember class and I managed to get rid of the exceptions too. Thanks for all your help.
Previous Topic:GEF dialog blocking command execution
Next Topic:Closing CTabs
Goto Forum:
  


Current Time: Sat Dec 20 13:05:08 GMT 2014

Powered by FUDForum. Page generated in 0.02632 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software