Created
February 6, 2012 18:18
-
-
Save anonymous/1753844 to your computer and use it in GitHub Desktop.
Human Readable JUnit test cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 01bb698 | |
Author: vvs | |
Date: Mon Feb 6 14:12:53 2012 +0100 | |
Human readable names for the test cases in JUnit view. | |
diff --git a/icons/full/obj16/human_readable.gif b/icons/full/obj16/human_readable.gif | |
new file mode 100644 | |
index 0000000..10aa790 | |
Binary files /dev/null and b/icons/full/obj16/human_readable.gif differ | |
diff --git a/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java b/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java | |
index b25f517..38b182c 100644 | |
--- a/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java | |
+++ b/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java | |
@@ -291,6 +291,7 @@ public final class JUnitMessages extends NLS { | |
public static String TestRunnerViewPart_show_execution_time; | |
public static String TestRunnerViewPart_show_failures_only; | |
+ public static String TestRunnerViewPart_human_readable; | |
public static String TestRunnerViewPart_hierarchical_layout; | |
public static String TestSessionLabelProvider_testName_elapsedTimeInSeconds; | |
diff --git a/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.properties b/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.properties | |
index 4fbd25e..1813360 100644 | |
--- a/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.properties | |
+++ b/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.properties | |
@@ -71,6 +71,7 @@ TestRunnerViewPart_select_test_run=&Select a test run: | |
TestRunnerViewPart_stopaction_tooltip=Stop JUnit Test Run | |
TestRunnerViewPart_show_execution_time=Show Execution &Time | |
TestRunnerViewPart_show_failures_only=Show &Failures Only | |
+TestRunnerViewPart_human_readable=Human &Readable Test Names | |
TestRunnerViewPart_rerunaction_label=Rerun Test | |
TestRunnerViewPart_rerunaction_tooltip=Rerun Test | |
TestRunnerViewPart_hierarchical_layout=Show Tests in &Hierarchy | |
diff --git a/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java b/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java | |
index d4d9dd6..4027a6e 100644 | |
--- a/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java | |
+++ b/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java | |
@@ -216,6 +216,7 @@ public class TestRunnerViewPart extends ViewPart { | |
private IHandlerActivation fRerunFailedFirstActivation; | |
private Action fFailuresOnlyFilterAction; | |
+ private Action fHumanReadableNamesAction; | |
private ScrollLockAction fScrollLockAction; | |
private ToggleOrientationAction[] fToggleOrientationActions; | |
private ShowTestHierarchyAction fShowTestHierarchyAction; | |
@@ -262,6 +263,8 @@ public class TestRunnerViewPart extends ViewPart { | |
static final String TAG_TRACEFILTER= "tracefilter"; //$NON-NLS-1$ | |
static final String TAG_ORIENTATION= "orientation"; //$NON-NLS-1$ | |
static final String TAG_SCROLL= "scroll"; //$NON-NLS-1$ | |
+ static final String TAG_HUMAN_READABLE= "human_readable"; //$NON-NLS-1$ | |
+ | |
/** | |
* @since 3.2 | |
*/ | |
@@ -1023,6 +1026,19 @@ public class TestRunnerViewPart extends ViewPart { | |
} | |
} | |
+ private class HumanReadableNamesAction extends Action { | |
+ public HumanReadableNamesAction() { | |
+ super(JUnitMessages.TestRunnerViewPart_human_readable, AS_CHECK_BOX); | |
+ setToolTipText(JUnitMessages.TestRunnerViewPart_human_readable); | |
+ setImageDescriptor(JUnitPlugin.getImageDescriptor("obj16/human_readable.gif")); //$NON-NLS-1$ | |
+ } | |
+ | |
+ @Override | |
+ public void run() { | |
+ setHumanReadableNames(isChecked()); | |
+ } | |
+ } | |
+ | |
private class ShowTimeAction extends Action { | |
public ShowTimeAction() { | |
@@ -1132,6 +1148,8 @@ public class TestRunnerViewPart extends ViewPart { | |
// int activePage= fTabFolder.getSelectionIndex(); | |
// memento.putInteger(TAG_PAGE, activePage); | |
memento.putString(TAG_SCROLL, fScrollLockAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ | |
+ memento.putString(TAG_HUMAN_READABLE, fHumanReadableNamesAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ | |
+ | |
int weigths[]= fSashForm.getWeights(); | |
int ratio= (weigths[0] * 1000) / (weigths[0] + weigths[1]); | |
memento.putInteger(TAG_RATIO, ratio); | |
@@ -1164,6 +1182,12 @@ public class TestRunnerViewPart extends ViewPart { | |
setAutoScroll(!fScrollLockAction.isChecked()); | |
} | |
+ String humanReadable = memento.getString(TAG_HUMAN_READABLE); | |
+ if (humanReadable != null) { | |
+ fHumanReadableNamesAction.setChecked(humanReadable.equals("true")); //$NON-NLS-1$ | |
+ setHumanReadableNames(fHumanReadableNamesAction.isChecked()); | |
+ } | |
+ | |
Integer layout= memento.getInteger(TAG_LAYOUT); | |
int layoutValue= LAYOUT_HIERARCHICAL; | |
if (layout != null) | |
@@ -1905,6 +1929,8 @@ action enablement | |
fFailuresOnlyFilterAction= new FailuresOnlyFilterAction(); | |
+ fHumanReadableNamesAction = new HumanReadableNamesAction(); | |
+ | |
fScrollLockAction= new ScrollLockAction(this); | |
fScrollLockAction.setChecked(!fAutoScroll); | |
@@ -1920,6 +1946,7 @@ action enablement | |
toolBar.add(fNextAction); | |
toolBar.add(fPreviousAction); | |
toolBar.add(fFailuresOnlyFilterAction); | |
+ toolBar.add(fHumanReadableNamesAction); | |
toolBar.add(fScrollLockAction); | |
toolBar.add(new Separator()); | |
toolBar.add(fRerunLastTestAction); | |
@@ -2144,6 +2171,10 @@ action enablement | |
setFilterAndLayout(failuresOnly, fLayout); | |
} | |
+ void setHumanReadableNames(boolean checked) { | |
+ fTestViewer.setShowHumanReadableNames(checked); | |
+ } | |
+ | |
private void setLayoutMode(int mode) { | |
setFilterAndLayout(fFailuresOnlyFilterAction.isChecked(), mode); | |
} | |
diff --git a/src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java b/src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java | |
index 30c56e4..5f5264c 100644 | |
--- a/src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java | |
+++ b/src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java | |
@@ -39,6 +39,7 @@ public class TestSessionLabelProvider extends LabelProvider implements IStyledLa | |
private final TestRunnerViewPart fTestRunnerPart; | |
private final int fLayoutMode; | |
private final NumberFormat timeFormat; | |
+ private boolean showHumanReadableNames; | |
private boolean fShowTime; | |
@@ -97,13 +98,31 @@ public class TestSessionLabelProvider extends LabelProvider implements IStyledLa | |
private String getSimpleLabel(Object element) { | |
if (element instanceof ITestCaseElement) { | |
- return BasicElementLabels.getJavaElementName(((ITestCaseElement) element).getTestMethodName()); | |
+ String testCaseName = BasicElementLabels.getJavaElementName(((ITestCaseElement) element).getTestMethodName()); | |
+ if (showHumanReadableNames) { | |
+ testCaseName = prettifyTestMethod(testCaseName); | |
+ } | |
+ return testCaseName; | |
} else if (element instanceof ITestSuiteElement) { | |
return BasicElementLabels.getJavaElementName(((ITestSuiteElement) element).getSuiteTypeName()); | |
} | |
return null; | |
} | |
+ private static String prettifyTestMethod(String testMethod) { | |
+ StringBuilder buf = new StringBuilder(); | |
+ for (int pos = 0; pos < testMethod.length(); pos++) { | |
+ char ch = testMethod.charAt(pos); | |
+ if ( pos > 0 && Character.isUpperCase(ch) ) { | |
+ buf.append(" "); | |
+ buf.append(Character.toLowerCase(ch)); | |
+ } else { | |
+ buf.append(ch); | |
+ } | |
+ } | |
+ return buf.toString(); | |
+ } | |
+ | |
@Override | |
public String getText(Object element) { | |
String label= getSimpleLabel(element); | |
@@ -173,4 +192,8 @@ public class TestSessionLabelProvider extends LabelProvider implements IStyledLa | |
fireLabelProviderChanged(new LabelProviderChangedEvent(this)); | |
} | |
+ public void setShowHumanReadableNames(boolean readableNames) { | |
+ this.showHumanReadableNames = readableNames; | |
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this)); | |
+ } | |
} | |
diff --git a/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java b/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java | |
index 434812a..987f74e 100644 | |
--- a/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java | |
+++ b/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java | |
@@ -314,6 +314,16 @@ public class TestViewer { | |
} | |
} | |
+ public synchronized void setShowHumanReadableNames(boolean readableNames) { | |
+ try { | |
+ fViewerbook.setRedraw(false); | |
+ fTreeLabelProvider.setShowHumanReadableNames(readableNames); | |
+ fTableLabelProvider.setShowHumanReadableNames(readableNames); | |
+ } finally { | |
+ fViewerbook.setRedraw(true); | |
+ } | |
+ } | |
+ | |
public synchronized void setShowFailuresOnly(boolean failuresOnly, int layoutMode) { | |
/* | |
* Management of fTreeViewer and fTableViewer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment