Home » Eclipse Projects » SWTBot » "No tests found"
| |
Re: "No tests found" [message #19684 is a reply to message #19594] |
Thu, 05 February 2009 03:59 |
Ketan Padegaonkar 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 #20524 is a reply to message #19791] |
Mon, 09 February 2009 09:34 |
Csaba Koncz 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 #26745 is a reply to message #24337] |
Fri, 06 March 2009 12:05 |
Marko Tomljenovic 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 #26825 is a reply to message #26745] |
Fri, 06 March 2009 13:03 |
Ketan Padegaonkar 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();
> }
>
>
>
|
|
| | | |
Goto Forum:
Current Time: Mon Jan 13 16:28:38 GMT 2025
Powered by FUDForum. Page generated in 0.05343 seconds
|