diff options
| author | Paul Pazderski | 2019-04-25 20:25:16 +0000 |
|---|---|---|
| committer | Andrey Loskutov | 2019-04-28 16:28:11 +0000 |
| commit | aee90db6478394e1f04d79728846696847e43794 (patch) | |
| tree | b61ed3011d4175fec071719e7e231fae1671d7d2 | |
| parent | 42c135ba9f5ad8cc617146353068c34f9c48d5db (diff) | |
| download | eclipse.platform.ui-aee90db6478394e1f04d79728846696847e43794.tar.gz eclipse.platform.ui-aee90db6478394e1f04d79728846696847e43794.tar.xz eclipse.platform.ui-aee90db6478394e1f04d79728846696847e43794.zip | |
Bug 546756 - [tests] Log test start/end for all testsI20190429-1800I20190429-0240I20190428-1800
Most classes extend UITestCase and inherit a consistent logging of test
setup and teardown. This adds the same logging for all JUnit4 tests not
inheriting UITestCase.
Change-Id: I04a30786abaca822401d30010bb85736d509c87b
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
17 files changed, 150 insertions, 3 deletions
diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java new file mode 100644 index 00000000000..81911cb51a6 --- /dev/null +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2019 Paul Pazderski and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Paul Pazderski - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.tests.harness.util; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** + * Util to help on consistent logging of test runs. + */ +public final class TestRunLogUtil { + + private static final String LINE_BREAK = System.getProperty("line.separator"); //$NON-NLS-1$ + + /** + * A {@link TestWatcher} to log test start and end. Should be added as @Rule in + * every JUnit4 test class (which not already extends {@link UITestCase}) as + * + * <pre> + * @Rule + * public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; + * </pre> + * + * Note: field must be public or JUnit4 will complain. + */ + public static TestWatcher LOG_TESTRUN = new TestWatcher() { + @Override + protected void starting(Description description) { + System.out.println(formatTestStartMessage(description.getMethodName())); + } + + @Override + protected void finished(Description description) { + System.out.println(formatTestFinishedMessage(description.getMethodName())); + } + }; + + /** + * Create message used to log start of a test. + * + * @param testName name of started test + * @return message used to log test start + */ + public static String formatTestStartMessage(String testName) { + return "----- " + testName + LINE_BREAK + testName + ": setUp..."; //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Create message used to log end of a test. + * + * @param testName name of finished test + * @return message used to log test end + */ + public static String formatTestFinishedMessage(String testName) { + return testName + ": tearDown...\n"; //$NON-NLS-1$ + } + + private TestRunLogUtil() { + } +} diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java index e9885b14e41..525b3f4f2ed 100644 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java @@ -222,8 +222,7 @@ public abstract class UITestCase extends TestCase { super.setUp(); fWorkbench = PlatformUI.getWorkbench(); String name = runningTest != null ? runningTest : this.getName(); - trace("----- " + name); //$NON-NLS-1$ - trace(name + ": setUp..."); //$NON-NLS-1$ + trace(TestRunLogUtil.formatTestStartMessage(name)); addWindowListener(); doSetUp(); @@ -252,7 +251,7 @@ public abstract class UITestCase extends TestCase { @Override public final void tearDown() throws Exception { String name = runningTest != null ? runningTest : this.getName(); - trace(name + ": tearDown...\n"); //$NON-NLS-1$ + trace(TestRunLogUtil.formatTestFinishedMessage(name)); removeWindowListener(); doTearDown(); fWorkbench = null; diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java index edaec6caed1..31b5a609a70 100644 --- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java +++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/AbstractFieldAssistTestCase.java @@ -24,10 +24,15 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestWatcher; public abstract class AbstractFieldAssistTestCase { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** * The window that is being tested. diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java index e128595a083..54d308da869 100644 --- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/fieldassist/ContentProposalAdapterTest.java @@ -27,11 +27,16 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class ContentProposalAdapterTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** * A shell that hosts the decorated text control diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/resources/FontRegistryTest.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/resources/FontRegistryTest.java index b578d9f6666..44986704b03 100644 --- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/resources/FontRegistryTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/resources/FontRegistryTest.java @@ -19,9 +19,14 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class FontRegistryTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; @Test public void testBug544026() { diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/MultipleWindowsTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/MultipleWindowsTest.java index 309ad7a0d48..c1f72c9e43e 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/MultipleWindowsTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/MultipleWindowsTest.java @@ -19,15 +19,21 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * A set of tests for multiple monitor situations that ensures interactions are * isolated to the respective window. */ public class MultipleWindowsTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; + IWorkbench wb; IWorkbenchWindow win1; IWorkbenchWindow win2; diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/PatternFilterTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/PatternFilterTest.java index a3ee208db56..f7bac8bd5d5 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/PatternFilterTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/PatternFilterTest.java @@ -23,10 +23,15 @@ import org.eclipse.jface.viewers.ContentViewer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.dialogs.PatternFilter; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class PatternFilterTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; private class MockViewer extends ContentViewer { diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/Bug397302Tests.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/Bug397302Tests.java index bcc64ae1bfc..67330656ab6 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/Bug397302Tests.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/Bug397302Tests.java @@ -20,14 +20,19 @@ import java.util.Map; import org.eclipse.ui.AbstractSourceProvider; import org.eclipse.ui.ISourceProviderListener; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * @since 3.5 * */ public class Bug397302Tests { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** * @since 3.5 diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryReaderTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryReaderTest.java index 17c09b10e7f..1f65b1222fd 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryReaderTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryReaderTest.java @@ -22,12 +22,17 @@ import static org.mockito.Mockito.verify; import org.eclipse.ui.internal.ide.registry.MarkerHelpRegistry; import org.eclipse.ui.internal.ide.registry.MarkerHelpRegistryReader; import org.eclipse.ui.internal.ide.registry.MarkerQuery; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * The test class for {@link MarkerHelpRegistryReader}. */ public class MarkerHelpRegistryReaderTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** * Tests if the matchChildren flag of the contributions to the markerHelp diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryTest.java index 04f62ae9295..66b8ffb243d 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerHelpRegistryTest.java @@ -25,14 +25,19 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.ui.internal.ide.registry.MarkerHelpRegistry; import org.eclipse.ui.internal.ide.registry.MarkerHelpRegistryReader; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * The test class for {@link MarkerHelpRegistry}. */ public class MarkerHelpRegistryTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; static final String ATT_HELP_CONTEXT = "helpContext"; static final String ATT_HAS_HELP = "hasHelp"; diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerQueryTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerQueryTest.java index 4315d3ea4a9..fe2b94b0ed4 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerQueryTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerQueryTest.java @@ -21,14 +21,19 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.ui.internal.ide.registry.MarkerQuery; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * The test class for {@link MarkerQuery}. */ public class MarkerQueryTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; private IMarker marker; private IMarker child_marker; diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/preferences/ZoomAndPreferencesFontTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/preferences/ZoomAndPreferencesFontTest.java index 23612906b08..9097b8d54ce 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/preferences/ZoomAndPreferencesFontTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/preferences/ZoomAndPreferencesFontTest.java @@ -35,19 +35,24 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage; import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * @since 3.11 * */ public class ZoomAndPreferencesFontTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; private static IProject project; private static IFile file; diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java index fcf7c5750f6..0622170411b 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java @@ -24,10 +24,15 @@ import java.util.List; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.internal.progress.JobInfo; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class JobInfoTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java index cae61624e6f..d7dc7b6210b 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java @@ -24,10 +24,15 @@ import java.util.List; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.internal.progress.JobInfo; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class JobInfoTestOrdering { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; private List<JobInfo> jobinfos = new ArrayList<>(); diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/ProgressAnimationItemTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/ProgressAnimationItemTest.java index 873e823ac05..3d98d19d9cd 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/ProgressAnimationItemTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/ProgressAnimationItemTest.java @@ -35,11 +35,17 @@ import org.eclipse.ui.internal.progress.ProgressAnimationItem; import org.eclipse.ui.internal.progress.ProgressManager; import org.eclipse.ui.internal.progress.ProgressRegion; import org.eclipse.ui.progress.IProgressConstants; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; public class ProgressAnimationItemTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; + private Shell shell; private ProgressAnimationItem animationItem; diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/ShellClosingTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/ShellClosingTest.java index 25632791dba..76881cb2cb4 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/ShellClosingTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/ShellClosingTest.java @@ -16,12 +16,17 @@ package org.eclipse.ui.tests.quickaccess; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; /** * @since 3.5 */ public class ShellClosingTest { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; /** * Bug 433746: dispose SearchField shell diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/releng/PluginActivationTests.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/releng/PluginActivationTests.java index 58a39e8d34f..391b1fc14a5 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/releng/PluginActivationTests.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/releng/PluginActivationTests.java @@ -24,9 +24,12 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestWatcher; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; @@ -44,6 +47,8 @@ import org.osgi.framework.FrameworkUtil; */ public class PluginActivationTests { + @Rule + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; private static String[] NOT_ACTIVE_BUNDLES = new String[] { "org.apache.xerces", |
