Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » "No tests found"
"No tests found" [message #19594] Wed, 04 February 2009 15:56 Go to next message
David Pochet is currently offline David PochetFriend
Messages: 10
Registered: July 2009
Junior Member
Hi all,

I previously used SWTBOT 1.x version, downloaded from SF update site.
I migrated today to 2.0.0.140 version, downloaded from Eclipse.org update
site.

Since that, I'm unable to run SWTBot test cases...
I restarted from the begining, writing a simple test plug-in, with 2
JUnit3 tests cases:
* one simple test case
* one SWTBOT eclipse test case

At runtime (as a SWTBOT run config):
* simple test case runs correctly
* SWTBOT test case is not found:

junit.framework.AssertionFailedError: No tests found in my.DummyBotTest
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:130)
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:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:63)
at
org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:122)
at
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
at java.lang.Thread.run(Unknown Source)


Here is my test case code:

package my;

import org.eclipse.swtbot.eclipse.finder.SWTBotEclipseTestCase;

public class DummyBotTest extends SWTBotEclipseTestCase
{
public void test_Dummy() throws Exception
{
bot.shell ( "Dummy Shell Test" ).activate ();
bot.button ();
bot.view ( "Dummy" );
}
}

Maybe I missed something?
Thx for your help...
Re: "No tests found" [message #19639 is a reply to message #19594] Wed, 04 February 2009 21:18 Go to previous messageGo to next message
Karen is currently offline KarenFriend
Messages: 4
Registered: July 2009
Junior Member
I see the same symptom. Very interested in a response...
Re: "No tests found" [message #19684 is a reply to message #19594] Thu, 05 February 2009 03:59 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Please hold on. The eclipse CVS/SVN servers are having hiccups after an
uptime of about 1.5 years, and the webmasters are looking into it.

In the meanwhile I'd recommend using the update site at
http://download.eclipse.org/technology/swtbot/dev-build/upda te-site/ and
use revision 2.0.0.133.

There's no api change, so there's probably some configuration missing
between the revisions, that's causing this issue.

-- Ketan

On 4/2/09 21:26, David Pochet wrote:
> Hi all,
>
> I previously used SWTBOT 1.x version, downloaded from SF update site.
> I migrated today to 2.0.0.140 version, downloaded from Eclipse.org
> update site.
>
> Since that, I'm unable to run SWTBot test cases...
> I restarted from the begining, writing a simple test plug-in, with 2
> JUnit3 tests cases:
> * one simple test case
> * one SWTBOT eclipse test case
>
> At runtime (as a SWTBOT run config):
> * simple test case runs correctly
> * SWTBOT test case is not found:
>
> junit.framework.AssertionFailedError: No tests found in my.DummyBotTest
> at junit.framework.Assert.fail(Assert.java:47)
> at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
> at junit.framework.TestCase.runBare(TestCase.java:130)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:120)
> at junit.framework.TestSuite.runTest(TestSuite.java:230)
> at junit.framework.TestSuite.run(TestSuite.java:225)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:130)
>
> 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:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>
> at
> org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main( RemotePluginTestRunner.java:63)
>
> at
> org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(U ITestApplication.java:122)
>
> at
> org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
>
> at java.lang.Thread.run(Unknown Source)
>
>
> Here is my test case code:
>
> package my;
>
> import org.eclipse.swtbot.eclipse.finder.SWTBotEclipseTestCase;
>
> public class DummyBotTest extends SWTBotEclipseTestCase
> {
> public void test_Dummy() throws Exception
> {
> bot.shell ( "Dummy Shell Test" ).activate ();
> bot.button ();
> bot.view ( "Dummy" );
> }
> }
>
> Maybe I missed something?
> Thx for your help...
>
Re: "No tests found" [message #19729 is a reply to message #19684] Thu, 05 February 2009 07:05 Go to previous messageGo to next message
David Pochet is currently offline David PochetFriend
Messages: 10
Registered: July 2009
Junior Member
Since yesterday I tried on another computer, with 2.0.0.dev-133
--> same symptoms

After investigations, I found that my test case is considered as if it was
not implementing the Test interface:
* that's why no test methods are found, since the test "while
(Test.class.isAssignableFrom(superClass)) {" (JUnit TestSuite class) is
always failling
* if I try to manually instantiate my class, and force cast to Test
interface, I get a Cast Exception...

Don't understand anymore...

If this is a regression (and not a config error on my side), is it
possible to retrieve an older functionnal SWTBOT build from somewhere?

Thanks
Re: "No tests found" [message #19750 is a reply to message #19684] Thu, 05 February 2009 08:31 Go to previous messageGo to next message
hugulas chen is currently offline hugulas chenFriend
Messages: 10
Registered: July 2009
Junior Member
I still have this problem although I installed the swtbot from dev-build
update site.
Re: "No tests found" [message #19791 is a reply to message #19750] Thu, 05 February 2009 09:25 Go to previous messageGo to next message
David Pochet is currently offline David PochetFriend
Messages: 10
Registered: July 2009
Junior Member
I get a workaround:
if I make my class extending JUnit TestCase, and no more
SWTBotEclipseTestCase, and I add the bot instance to my class ("protected
SWTEclipseBot bot = new SWTEclipseBot();"), it just works!

Obviously, I loose the assert & other methods brought by SWTBotTestCase,
but personnaly I don't use them.

However, I'm interresed in knowing the root cause of the issue...
Re: "No tests found" [message #19835 is a reply to message #19791] Thu, 05 February 2009 10:26 Go to previous messageGo to next message
hugulas chen is currently offline hugulas chenFriend
Messages: 10
Registered: July 2009
Junior Member
I remove junit 4.5 and remove the bundle=4.5.0 in all manifest.mf.
It works.
The junit 4.5 is broken.
Re: "No tests found" [message #19880 is a reply to message #19791] Thu, 05 February 2009 10:38 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Thanks that's a good feedback for me start with, I appreciate your
investigation. I'll update the build once things are fixed.

-- Ketan

On 5/2/09 14:55, David Pochet wrote:
> I get a workaround:
> if I make my class extending JUnit TestCase, and no more
> SWTBotEclipseTestCase, and I add the bot instance to my class
> ("protected SWTEclipseBot bot = new SWTEclipseBot();"), it just works!
>
> Obviously, I loose the assert & other methods brought by SWTBotTestCase,
> but personnaly I don't use them.
>
> However, I'm interresed in knowing the root cause of the issue...
>
Re: "No tests found" [message #20009 is a reply to message #19880] Thu, 05 February 2009 22:00 Go to previous messageGo to next message
Karen is currently offline KarenFriend
Messages: 4
Registered: July 2009
Junior Member
Please make sure the samples swtbot code in the SVN repository works. I
noticed one note in this chain says the code works if you do not use junit
4.5. When I first encountered this error, I was trying to get the
org.rcpmail.test sample code to work so I could get familiar with coding
using swtbot.

Although when I checked it out of CVS, the dependency in the manifest file
said junit 4, there were no annotations in the code, so I changed the
dependency back to junit 3 in my project explorer.

Also, fyi, my results were consistent with David's. If I remove
SWTBotEclipseTestCase and extend junit.framework.TestCase, I do not see
the error. But that doesn't help getting the sample code to run!
Re: "No tests found" [message #20524 is a reply to message #19791] Mon, 09 February 2009 09:34 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hello,

The reason for your test cases not implementing junit.framework.Test is
that there are two such interfaces: one in org.junit (which is version 3
and referenced by your test plugin) and one in org.junit4 (used by
SWTBot).

org.junit4 does not require org.junit, it simply duplicates the
junit.framework.* classes, so the two interfaces are not considered the
same.

So when you explicitly implement Test in your test case you get the one
from junit 3.8 (I do not know why) and that's why it works.

Clarification: I have org.junit4_4.3 as, similarly to others, I am unable
to get junit4_4.5 from the update site.

David Pochet wrote:

> I get a workaround:
> if I make my class extending JUnit TestCase, and no more
> SWTBotEclipseTestCase, and I add the bot instance to my class ("protected
> SWTEclipseBot bot = new SWTEclipseBot();"), it just works!

> Obviously, I loose the assert & other methods brought by SWTBotTestCase,
> but personnaly I don't use them.

> However, I'm interresed in knowing the root cause of the issue...
Re: "No tests found" [message #20540 is a reply to message #20524] Mon, 09 February 2009 16:48 Go to previous messageGo to next message
Karen is currently offline KarenFriend
Messages: 4
Registered: July 2009
Junior Member
It is true that junit4 tests do not extend from junit.framework. However,
I looked in the SVN repository and found that the swtbot class
SWTBotTestCase does extend from junit.framework.TestCase. Plus, the
sample code does not contain annotations for junit4. I am not sure how
junit works, but if it finds junit.framework in the heirarchy, does it
automatically enforce junit3 requirements on the test case?
Re: "No tests found" [message #20558 is a reply to message #20540] Tue, 10 February 2009 09:17 Go to previous messageGo to next message
Marc is currently offline MarcFriend
Messages: 32
Registered: July 2009
Member
Hi,
@Karen

If you want the sample code to run, you should try the net.sf version
(see http://swtbot.sourceforge.net/index.html)
At least you'll be able to run the example.

@all
Same problem for me, the workarround mentioned worked for me.

Marc
Re: "No tests found" [message #20567 is a reply to message #20558] Wed, 11 February 2009 09:27 Go to previous messageGo to next message
hugulas chen is currently offline hugulas chenFriend
Messages: 10
Registered: July 2009
Junior Member
My workround is
remove org.junit4.5.0 from plugins dir and
replace "org.junit4;bundle-version="4.5.0" to "org.junit4" in all swtbotf
plugin MANIFEST.MF.
Re: "No tests found" [message #20576 is a reply to message #20558] Wed, 11 February 2009 09:51 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
I think I've fixed most issues in revision 160 available on the dev
site. What problem and work around are you referring to ?

-- Ketan

On 10/2/09 14:47, Marc wrote:
> Hi,
> @Karen
>
> If you want the sample code to run, you should try the net.sf version
> (see http://swtbot.sourceforge.net/index.html)
> At least you'll be able to run the example.
>
> @all
> Same problem for me, the workarround mentioned worked for me.
>
> Marc
>
Re: "No tests found" [message #20584 is a reply to message #20576] Wed, 11 February 2009 10:14 Go to previous messageGo to next message
Marc is currently offline MarcFriend
Messages: 32
Registered: July 2009
Member
Unfortunately it seems not.
I've got the 2.0.0.160 update and still faces the "no test found" problem.

junit.framework.AssertionFailedError: No tests found in
org.rcpmail.MyTests_clean

Changing SWTBotEclipseTestCase to TestCase
and adding "protected SWTEclipseBot bot = new SWTEclipseBot();"

is the work around I'm refering to.

Bye

nb: I'll be more explicit next time ;)

Ketan Padegaonkar wrote:

> I think I've fixed most issues in revision 160 available on the dev
> site. What problem and work around are you referring to ?

> -- Ketan

> On 10/2/09 14:47, Marc wrote:
>> Hi,
>> @Karen
>>
>> If you want the sample code to run, you should try the net.sf version
>> (see http://swtbot.sourceforge.net/index.html)
>> At least you'll be able to run the example.
>>
>> @all
>> Same problem for me, the workarround mentioned worked for me.
>>
>> Marc
>>
Re: "No tests found" [message #24337 is a reply to message #20584] Wed, 25 February 2009 18:08 Go to previous messageGo to next message
Karen is currently offline KarenFriend
Messages: 4
Registered: July 2009
Junior Member
If I go back to the net.sf code, I have to change the package names and
apis back to the old ones, yes? I am investigating using swtbot in
creating test cases for our product and developers/testers will not be
happy if they have to learn one api and then port their test cases over to
the new packages/apis.

BTW, I had problems with the junit 4.5 .jar file shipped with swtbot. I
could not get regular junit4 (not swtbot) tests to run and noticed that it
was using the junit 4.5 .jar file shipped with swtbot. When I removed
swtbot from my environment altogether and used the junit .jar file shipped
with Data Studio, then everything was fine and my life was happy again.

IAre these issues going to be fixed anytime soon? I've temporarily
abandoned our swtbot effort because of these problems.
Re: "No tests found" [message #26745 is a reply to message #24337] Fri, 06 March 2009 12:05 Go to previous messageGo to next message
Marko Tomljenovic is currently offline Marko TomljenovicFriend
Messages: 62
Registered: July 2009
Member
Hello all,
because of that reason (somehow the test runner assumes that the test is a
JUnit4 test but it is a JUnit 3 test) I have created two base test classes
that contain basically (without taking the screenshot) the same
functionality as the original swtbot testcase classes.

In addition I have reimplemented the runBare() method so that the test
runs in a separate thread to be able to use it in a pde build (not yet
tested).

Maybe some of you could use these classes. Since I have not tested them
with many tests any feedback is appreciated.

PS I am using the dev release 2.0.0 build 187

Here the first class:
++++++++++++++++++++++

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import junit.framework.AssertionFailedError;
import junit.framework.TestCase;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.SWTBotAssert;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;


/**
* Class that is more or less a copy from the original {@link
SWTBotTestCase}.
* <p>
* The copy is done because when using the original class the tests are
not running because of
* "AssertionFailedError: No tests found in ...". The reason of that is:
Because of some JUnit4 dependencies in the
* swtbot plugins JUnit4 tests are searched for and not JUnit3 "test.."
methods.
*
* @author Marko Tomljenovic
*/
public abstract class MySWTBotTestCase extends TestCase {

/**
* Test timeout in milli seconds
*/
protected long timeout = 1800000;

/**
* Overides the runBare method to TestCase to add the ability to capture
a screen shot when an error is thrown. The
* screenshot is saved to a file in the current run directory inside a
folder called {@code screenshots} that gets
* created if it does not already exist. The screenshot will be saved
with the file {@code
* screenshots/screenshot-<classname>.<testname>.png}
*
* @see junit.framework.TestCase#runBare()
* @throws Throwable Thrown if an error occurs during running.
*/
@Override
public void runBare() throws Throwable {
final Throwable[] testThrowables = new Throwable[1];
Runnable test = new Runnable() {

@SuppressWarnings("synthetic-access")
@Override
public void run() {
try {
MySWTBotTestCase.super.runBare();
}
catch (Throwable e) {
testThrowables[0] = e;
}
}
};
final ExecutorService executor = Executors.newSingleThreadExecutor();
final long testStartTime = System.currentTimeMillis();
executor.execute(test);
executor.shutdown();

final Display display = getCurrentDisplay();
if (display != null) {
final Throwable[] uiDispatchThrowable = new Throwable[1];
display.syncExec(new Runnable() {

@Override
public void run() {
boolean testFinished = executor.isTerminated();
long testDuration = System.currentTimeMillis() - testStartTime;
// Loop until test is finished
while (!testFinished && (testDuration <
MySWTBotTestCase.this.timeout)) {
// synchronize the ui thread so that the ui events created by
the tests can be processed
int dispatchCtr = 0;
final int maxDispatchBeforeContinueLoop = 100;
try {
while (display.readAndDispatch() && (dispatchCtr <
maxDispatchBeforeContinueLoop)) {
dispatchCtr++;
}
}
catch (Exception e) {
uiDispatchThrowable[0] = e;
}
testFinished = executor.isTerminated();
}
if (!testFinished) {
throw new AssertionFailedError("The test \"" +
this.getClass().getSimpleName() + "." + getName() +
"\" has not finished in " + MySWTBotTestCase.this.timeout
/ 1000 +
" seconds! Therefore it is assumed that the test has
failed!");
}
}
});
if (uiDispatchThrowable[0] != null) {
throw uiDispatchThrowable[0];
}
}
if (testThrowables[0] != null) {
throw testThrowables[0];
}
}

/**
* @return the swt display for the currently active swt based
application.
*/
protected Display getCurrentDisplay() {
return Display.getCurrent();
}

/**
* An instance of SWTBot that may be used
*/
protected SWTBot bot = new SWTBot();

/**
* Asserts that two widgets do not refer to the same object.
*
* @see #assertNotSame(String, Object, Object)
* @param expected the object you don't expect
* @param actual the object to compare to unexpected
*/
public static void assertNotSameWidget(final Widget expected, final
Widget actual) {
SWTBotAssert.assertNotSameWidget(expected, actual);
}

/**
* Asserts the two widgets do not refer to the same object. The message
will be used if the test fails.
*
* @param message the identifying message or null for the AssertionError
* @param expected the object you don't expect
* @param actual the object to compare to unexpected
*/
public static void assertNotSameWidget(final String message, final
Widget expected, final Widget actual) {
SWTBotAssert.assertNotSameWidget(message, expected, actual);
}

/**
* Asserts that the <code>needle</code> is contained within the
<code>hayStack</code>.
*
* @param needle the text to search in the <code>hayStack</code>.
* @param hayStack the text to look within.
*/
public static void assertContains(final String needle, final String
hayStack) {
SWTBotAssert.assertContains(needle, hayStack);
}

/**
* Asserts that the <code>needle</code> is not present in the
<code>hayStack</code>.
*
* @param needle the text to search in the <code>hayStack</code>.
* @param hayStack the text to look within.
*/
public static void assertDoesNotContain(final String needle, final
String hayStack) {
SWTBotAssert.assertDoesNotContain(needle, hayStack);
}

/**
* Asserts that two widgets refer to the same widget.
*
* @param expected the expected widget
* @param actual the widget to compare to expected
*/
public static void assertSameWidget(final Widget expected, final Widget
actual) {
SWTBotAssert.assertSameWidget(expected, actual);
}

/**
* Asserts that two widgets refer to the same widgets.
*
* @param message the identifying message or <code>null</code> for the
AssertionError
* @param expected the expected widget
* @param actual the widget to compare to expected
*/
public static void assertSameWidget(final String message, final Widget
expected, final Widget actual) {
SWTBotAssert.assertSameWidget(message, expected, actual);
}

/**
* Assert that the given string is the same as the widgets text.
*
* @param expected the expected text
* @param widget the widget to get the text from to compare.
*/
public static void assertText(final String expected, final Widget
widget) {
SWTBotAssert.assertText(expected, widget);
}

/**
* Assert that the given string is the same as the widgets text.
*
* @param expected the expected text
* @param widget the widget to get the text from to compare.
*/
public static void assertText(final String expected, final
AbstractSWTBot<? extends Widget> widget) {
SWTBotAssert.assertText(expected, widget);
}

/**
* Assert that the text on the widget contains the expected text.
*
* @param expected the expected text.
* @param widget the widget
*/
public static void assertTextContains(final String expected, final
Widget widget) {
SWTBotAssert.assertTextContains(expected, widget);
}

/**
* Assert that the text on the widget contains the expected text.
*
* @param expected the expected text
* @param widget the widget
*/
public static void assertTextContains(final String expected, final
AbstractSWTBot<? extends Widget> widget) {
SWTBotAssert.assertTextContains(expected, widget);
}

/**
* Assert that the text on the widget does not contain the expected text.
*
* @param expected the expected text
* @param widget the widget
*/
public static void assertTextDoesNotContain(final String expected, final
Widget widget) {
SWTBotAssert.assertTextDoesNotContain(expected, widget);
}

/**
* Assert that the text on the widget does not contain the expected text.
*
* @param expected the expected text
* @param widget the widget
*/
public static void assertTextDoesNotContain(final String expected, final
AbstractSWTBot<? extends Widget> widget) {
SWTBotAssert.assertTextDoesNotContain(expected, widget);
}

/**
* Asserts that the widget is enabled.
*
* @param widget the widget.
*/
public static void assertEnabled(final AbstractSWTBot<? extends Widget>
widget) {
SWTBotAssert.assertEnabled(widget);
}

/**
* Asserts that the widget is not enabled.
*
* @param widget the widget.
*/
public static void assertNotEnabled(final AbstractSWTBot<? extends
Widget> widget) {
SWTBotAssert.assertNotEnabled(widget);
}

/**
* Asserts that the widget is visible.
*
* @param widget the widget.
*/
public static void assertVisible(final AbstractSWTBot<? extends Widget>
widget) {
SWTBotAssert.assertVisible(widget);
}

/**
* Asserts that the widget is not visible.
*
* @param widget the widget.
*/
public static void assertNotVisible(final AbstractSWTBot<? extends
Widget> widget) {
SWTBotAssert.assertNotVisible(widget);
}

}



And the second one as well:
++++++++++++++++++++++++++++

import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
import org.eclipse.ui.PlatformUI;


/**
* This is a wrapper test case to the {@link MySWTBotTestCase} that adds
an eclipse bot instead of the standard bot.
*
* @author Marko Tomljenovic
*/
public abstract class MySWTBotEclipseTestCase extends MySWTBotTestCase {


/**
* {@inheritDoc}
*/
@Override
protected Display getCurrentDisplay() {
return PlatformUI.getWorkbench().getDisplay();
}

/**
* An instance of SWTEclipseBot.
*/
protected SWTEclipseBot bot = new SWTEclipseBot();
}
Re: "No tests found" [message #26784 is a reply to message #26745] Fri, 06 March 2009 12:28 Go to previous messageGo to next message
Marko Tomljenovic is currently offline Marko TomljenovicFriend
Messages: 62
Registered: July 2009
Member
There is a small bug in the first class.

Add the following line:
testDuration = System.currentTimeMillis() - testStartTime;

after this line:
testFinished = executor.isTerminated();

Sorry for that :)
Re: "No tests found" [message #26825 is a reply to message #26745] Fri, 06 March 2009 13:03 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Hi Marko,

Thanks for this input. I think I understand what the problem has been
all along.

I'd like to clarify that SWTBot does work with junit3 style tests, but
you need to depend on the junit4 plugin in order to do this.

The reason for this is the fact that the SWTBot launcher is compiled
against JUnit 4.x and gets confused when it sees your tests are running
against junit 3.x.

Could you please verify this behavior ? I'll update the user guide and
documentation about this particular case, the documentation is quite out
of date, and has not been updated in a while after the move to junit4.

-- Ketan

On 6/3/09 17:35, Marko Tomljenovic wrote:
> Hello all,
> because of that reason (somehow the test runner assumes that the test is
> a JUnit4 test but it is a JUnit 3 test) I have created two base test
> classes that contain basically (without taking the screenshot) the same
> functionality as the original swtbot testcase classes.
>
> In addition I have reimplemented the runBare() method so that the test
> runs in a separate thread to be able to use it in a pde build (not yet
> tested).
>
> Maybe some of you could use these classes. Since I have not tested them
> with many tests any feedback is appreciated.
>
> PS I am using the dev release 2.0.0 build 187
>
> Here the first class:
> ++++++++++++++++++++++
>
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
>
> import junit.framework.AssertionFailedError;
> import junit.framework.TestCase;
>
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Widget;
> import org.eclipse.swtbot.swt.finder.SWTBot;
> import org.eclipse.swtbot.swt.finder.SWTBotAssert;
> import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
> import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
>
>
> /**
> * Class that is more or less a copy from the original {@link
> SWTBotTestCase}.
> * <p>
> * The copy is done because when using the original class the tests are
> not running because of
> * "AssertionFailedError: No tests found in ...". The reason of that is:
> Because of some JUnit4 dependencies in the
> * swtbot plugins JUnit4 tests are searched for and not JUnit3 "test.."
> methods.
> * * @author Marko Tomljenovic
> */
> public abstract class MySWTBotTestCase extends TestCase {
>
> /**
> * Test timeout in milli seconds
> */
> protected long timeout = 1800000;
>
> /**
> * Overides the runBare method to TestCase to add the ability to capture
> a screen shot when an error is thrown. The
> * screenshot is saved to a file in the current run directory inside a
> folder called {@code screenshots} that gets
> * created if it does not already exist. The screenshot will be saved
> with the file {@code
> * screenshots/screenshot-<classname>.<testname>.png}
> * * @see junit.framework.TestCase#runBare()
> * @throws Throwable Thrown if an error occurs during running.
> */
> @Override
> public void runBare() throws Throwable {
> final Throwable[] testThrowables = new Throwable[1];
> Runnable test = new Runnable() {
>
> @SuppressWarnings("synthetic-access")
> @Override
> public void run() {
> try {
> MySWTBotTestCase.super.runBare();
> }
> catch (Throwable e) {
> testThrowables[0] = e;
> }
> }
> };
> final ExecutorService executor = Executors.newSingleThreadExecutor();
> final long testStartTime = System.currentTimeMillis();
> executor.execute(test);
> executor.shutdown();
>
> final Display display = getCurrentDisplay();
> if (display != null) {
> final Throwable[] uiDispatchThrowable = new Throwable[1];
> display.syncExec(new Runnable() {
>
> @Override
> public void run() {
> boolean testFinished = executor.isTerminated();
> long testDuration = System.currentTimeMillis() - testStartTime;
> // Loop until test is finished
> while (!testFinished && (testDuration < MySWTBotTestCase.this.timeout)) {
> // synchronize the ui thread so that the ui events created by the tests
> can be processed
> int dispatchCtr = 0;
> final int maxDispatchBeforeContinueLoop = 100;
> try {
> while (display.readAndDispatch() && (dispatchCtr <
> maxDispatchBeforeContinueLoop)) {
> dispatchCtr++;
> }
> }
> catch (Exception e) {
> uiDispatchThrowable[0] = e;
> }
> testFinished = executor.isTerminated();
> }
> if (!testFinished) {
> throw new AssertionFailedError("The test \"" +
> this.getClass().getSimpleName() + "." + getName() +
> "\" has not finished in " + MySWTBotTestCase.this.timeout / 1000 +
> " seconds! Therefore it is assumed that the test has failed!");
> }
> }
> });
> if (uiDispatchThrowable[0] != null) {
> throw uiDispatchThrowable[0];
> }
> }
> if (testThrowables[0] != null) {
> throw testThrowables[0];
> }
> }
>
> /**
> * @return the swt display for the currently active swt based application.
> */
> protected Display getCurrentDisplay() {
> return Display.getCurrent();
> }
>
> /**
> * An instance of SWTBot that may be used
> */
> protected SWTBot bot = new SWTBot();
>
> /**
> * Asserts that two widgets do not refer to the same object.
> * * @see #assertNotSame(String, Object, Object)
> * @param expected the object you don't expect
> * @param actual the object to compare to unexpected
> */
> public static void assertNotSameWidget(final Widget expected, final
> Widget actual) {
> SWTBotAssert.assertNotSameWidget(expected, actual);
> }
>
> /**
> * Asserts the two widgets do not refer to the same object. The message
> will be used if the test fails.
> * * @param message the identifying message or null for the AssertionError
> * @param expected the object you don't expect
> * @param actual the object to compare to unexpected
> */
> public static void assertNotSameWidget(final String message, final
> Widget expected, final Widget actual) {
> SWTBotAssert.assertNotSameWidget(message, expected, actual);
> }
>
> /**
> * Asserts that the <code>needle</code> is contained within the
> <code>hayStack</code>.
> * * @param needle the text to search in the <code>hayStack</code>.
> * @param hayStack the text to look within.
> */
> public static void assertContains(final String needle, final String
> hayStack) {
> SWTBotAssert.assertContains(needle, hayStack);
> }
>
> /**
> * Asserts that the <code>needle</code> is not present in the
> <code>hayStack</code>.
> * * @param needle the text to search in the <code>hayStack</code>.
> * @param hayStack the text to look within.
> */
> public static void assertDoesNotContain(final String needle, final
> String hayStack) {
> SWTBotAssert.assertDoesNotContain(needle, hayStack);
> }
>
> /**
> * Asserts that two widgets refer to the same widget.
> * * @param expected the expected widget
> * @param actual the widget to compare to expected
> */
> public static void assertSameWidget(final Widget expected, final Widget
> actual) {
> SWTBotAssert.assertSameWidget(expected, actual);
> }
>
> /**
> * Asserts that two widgets refer to the same widgets.
> * * @param message the identifying message or <code>null</code> for the
> AssertionError
> * @param expected the expected widget
> * @param actual the widget to compare to expected
> */
> public static void assertSameWidget(final String message, final Widget
> expected, final Widget actual) {
> SWTBotAssert.assertSameWidget(message, expected, actual);
> }
>
> /**
> * Assert that the given string is the same as the widgets text.
> * * @param expected the expected text
> * @param widget the widget to get the text from to compare.
> */
> public static void assertText(final String expected, final Widget widget) {
> SWTBotAssert.assertText(expected, widget);
> }
>
> /**
> * Assert that the given string is the same as the widgets text.
> * * @param expected the expected text
> * @param widget the widget to get the text from to compare.
> */
> public static void assertText(final String expected, final
> AbstractSWTBot<? extends Widget> widget) {
> SWTBotAssert.assertText(expected, widget);
> }
>
> /**
> * Assert that the text on the widget contains the expected text.
> * * @param expected the expected text.
> * @param widget the widget
> */
> public static void assertTextContains(final String expected, final
> Widget widget) {
> SWTBotAssert.assertTextContains(expected, widget);
> }
>
> /**
> * Assert that the text on the widget contains the expected text.
> * * @param expected the expected text
> * @param widget the widget
> */
> public static void assertTextContains(final String expected, final
> AbstractSWTBot<? extends Widget> widget) {
> SWTBotAssert.assertTextContains(expected, widget);
> }
>
> /**
> * Assert that the text on the widget does not contain the expected text.
> * * @param expected the expected text
> * @param widget the widget
> */
> public static void assertTextDoesNotContain(final String expected, final
> Widget widget) {
> SWTBotAssert.assertTextDoesNotContain(expected, widget);
> }
>
> /**
> * Assert that the text on the widget does not contain the expected text.
> * * @param expected the expected text
> * @param widget the widget
> */
> public static void assertTextDoesNotContain(final String expected, final
> AbstractSWTBot<? extends Widget> widget) {
> SWTBotAssert.assertTextDoesNotContain(expected, widget);
> }
>
> /**
> * Asserts that the widget is enabled.
> * * @param widget the widget.
> */
> public static void assertEnabled(final AbstractSWTBot<? extends Widget>
> widget) {
> SWTBotAssert.assertEnabled(widget);
> }
>
> /**
> * Asserts that the widget is not enabled.
> * * @param widget the widget.
> */
> public static void assertNotEnabled(final AbstractSWTBot<? extends
> Widget> widget) {
> SWTBotAssert.assertNotEnabled(widget);
> }
>
> /**
> * Asserts that the widget is visible.
> * * @param widget the widget.
> */
> public static void assertVisible(final AbstractSWTBot<? extends Widget>
> widget) {
> SWTBotAssert.assertVisible(widget);
> }
>
> /**
> * Asserts that the widget is not visible.
> * * @param widget the widget.
> */
> public static void assertNotVisible(final AbstractSWTBot<? extends
> Widget> widget) {
> SWTBotAssert.assertNotVisible(widget);
> }
>
> }
>
>
>
> And the second one as well:
> ++++++++++++++++++++++++++++
>
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
> import org.eclipse.ui.PlatformUI;
>
>
> /**
> * This is a wrapper test case to the {@link MySWTBotTestCase} that adds
> an eclipse bot instead of the standard bot.
> * * @author Marko Tomljenovic
> */
> public abstract class MySWTBotEclipseTestCase extends MySWTBotTestCase {
>
>
> /**
> * {@inheritDoc}
> */
> @Override
> protected Display getCurrentDisplay() {
> return PlatformUI.getWorkbench().getDisplay();
> }
>
> /**
> * An instance of SWTEclipseBot.
> */
> protected SWTEclipseBot bot = new SWTEclipseBot();
> }
>
>
>
Re: "No tests found" [message #26865 is a reply to message #26825] Fri, 06 March 2009 14:05 Go to previous messageGo to next message
Marko Tomljenovic is currently offline Marko TomljenovicFriend
Messages: 62
Registered: July 2009
Member
Hi
if you tell me how I can verifiy that I will do it!

What I can tell you is that if my test is subclassing from SWTBotTestCase
and I run it using the swtbot launcher I always get the message: No tests
found...

Greets Marko
Re: "No tests found" [message #27103 is a reply to message #26825] Tue, 10 March 2009 16:45 Go to previous messageGo to next message
Madhu Samuel is currently offline Madhu SamuelFriend
Messages: 199
Registered: July 2009
Senior Member
Hello Ketan,

I have updated the section "Getting started with SWTBot for Eclipse
Plugins" in the User Guide.

Regards,
Madhu


Re: "No tests found" [message #27142 is a reply to message #27103] Wed, 11 March 2009 10:32 Go to previous message
Kay-Uwe Graw is currently offline Kay-Uwe GrawFriend
Messages: 24
Registered: July 2009
Junior Member
I also have the no tests found error. My context in detail:

I have a plugin MyExtendedSWTBot with some additional functionality to
swtbot which depends on org.eclipse.swtbot.eclipse.finder,
org.eclipse.swtbot.swt.finder and org.junit (3.8.2) which are also
re-exported. I've written tests for my rcp application MyApplication which
are in an extra plugin MyApplicationTest. This plugin depends on
MyExtendedSWTBot.

Everything works fine with the last developer version from the old update
site swtbot 2.0.167. When I move to swtbot 2.0.187 I get the "No tests
found" - error. When I make MyExtendedSWTBot depending on org.junit4
(4.3.1) I get the exception:

No Classloader found for plug-in MyApplicationTest.

Based on Marko's idea I use the following solution:

I simply copy the classes SWTBotTestCase and SWTBotEclipseTestCase into
MyExtendedSWTBot and make SWTBotEclipseTestCase extend from the local
version of SWTBotTestCase instead from the original SWTBotTestCase class.
If I now extend my Tests from the "new" SWTBotEclipseTestCase class
erverything works fine again if MyExtendedSWTBot depends on org.junit
(3.8.2). With dependency to org.junit4 (4.3.1) I get the Classloader
exception as well.

It looks, there are still some unresolved org.junit 3<>4 issues. Anyway, I
can live with this solution but hopefully this will be solved properly.
Previous Topic:Improvement for captureScreenshot
Next Topic:Getting menu from chevron (drop down arrow)
Goto Forum:
  


Current Time: Mon Dec 22 22:16:47 GMT 2014

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

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