2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.execution
.testframework
.sm
.runner
.ui
;
18 import com
.intellij
.execution
.runners
.ExecutionEnvironment
;
19 import com
.intellij
.execution
.testframework
.TestConsoleProperties
;
20 import com
.intellij
.execution
.testframework
.sm
.Marker
;
21 import com
.intellij
.execution
.testframework
.sm
.runner
.BaseSMTRunnerTestCase
;
22 import com
.intellij
.execution
.testframework
.sm
.runner
.GeneralToSMTRunnerEventsConvertor
;
23 import com
.intellij
.execution
.testframework
.sm
.runner
.SMTestProxy
;
24 import com
.intellij
.openapi
.progress
.util
.ColorProgressBar
;
25 import com
.intellij
.openapi
.util
.Disposer
;
26 import com
.intellij
.openapi
.util
.Ref
;
27 import org
.jetbrains
.annotations
.NotNull
;
28 import org
.jetbrains
.annotations
.Nullable
;
30 import javax
.swing
.tree
.DefaultMutableTreeNode
;
31 import javax
.swing
.tree
.TreeModel
;
32 import javax
.swing
.tree
.TreePath
;
35 * @author Roman Chernyatchik
37 public class SMTestRunnerResultsFormTest
extends BaseSMTRunnerTestCase
{
38 private SMTRunnerConsoleView myConsole
;
39 private GeneralToSMTRunnerEventsConvertor myEventsProcessor
;
40 private TreeModel myTreeModel
;
41 private SMTestRunnerResultsForm myResultsViewer
;
42 private TestConsoleProperties myConsoleProperties
;
43 private SMTestProxy myTestsRootNode
;
46 protected void setUp() throws Exception
{
49 myConsoleProperties
= createConsoleProperties();
50 TestConsoleProperties
.HIDE_PASSED_TESTS
.set(myConsoleProperties
, false);
51 TestConsoleProperties
.OPEN_FAILURE_LINE
.set(myConsoleProperties
, false);
52 TestConsoleProperties
.SCROLL_TO_SOURCE
.set(myConsoleProperties
, false);
53 TestConsoleProperties
.SELECT_FIRST_DEFECT
.set(myConsoleProperties
, false);
54 TestConsoleProperties
.TRACK_RUNNING_TEST
.set(myConsoleProperties
, false);
56 final ExecutionEnvironment environment
= new ExecutionEnvironment();
58 myConsole
= new SMTRunnerConsoleView(myConsoleProperties
, environment
.getRunnerSettings(), environment
.getConfigurationSettings());
60 myResultsViewer
= myConsole
.getResultsViewer();
61 myTestsRootNode
= myResultsViewer
.getTestsRootNode();
62 myEventsProcessor
= new GeneralToSMTRunnerEventsConvertor(myResultsViewer
.getTestsRootNode());
63 myEventsProcessor
.addEventsListener(myResultsViewer
);
64 myTreeModel
= myResultsViewer
.getTreeView().getModel();
68 protected void tearDown() throws Exception
{
69 Disposer
.dispose(myEventsProcessor
);
70 Disposer
.dispose(myConsole
);
75 public void testGetTestsRootNode() {
76 assertNotNull(myTestsRootNode
);
78 myResultsViewer
.onTestingFinished(myTestsRootNode
);
79 assertNotNull(myResultsViewer
.getTestsRootNode());
82 public void testTestingStarted() {
83 myResultsViewer
.onTestingStarted(myTestsRootNode
);
85 assertTrue(myResultsViewer
.getStartTime() > 0);
86 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
87 assertEquals(0, myResultsViewer
.getTestsTotal());
90 public void testOnTestStarted() {
91 myResultsViewer
.onTestStarted(createTestProxy("some_test", myTestsRootNode
));
92 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
94 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
95 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
98 public void testCount() {
99 myResultsViewer
.onTestsCountInSuite(1);
101 assertEquals(1, myResultsViewer
.getTestsTotal());
103 myResultsViewer
.onTestStarted(createTestProxy("some_test", myTestsRootNode
));
104 assertEquals(1, myResultsViewer
.getTestsTotal());
106 // if exceeds - will be incremented
107 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
108 assertEquals(2, myResultsViewer
.getTestsTotal());
111 public void testCount_UnSet() {
112 myResultsViewer
.onTestStarted(createTestProxy("some_test", myTestsRootNode
));
113 assertEquals(0, myResultsViewer
.getTestsTotal());
115 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
116 assertEquals(0, myResultsViewer
.getTestsTotal());
118 // count will be updated only on tests finished if wasn't set
119 myResultsViewer
.onTestingFinished(myTestsRootNode
);
120 assertEquals(2, myResultsViewer
.getTestsTotal());
123 public void testOnTestFailure() {
124 final SMTestProxy test
= createTestProxy(myTestsRootNode
);
126 myResultsViewer
.onTestStarted(test
);
127 myResultsViewer
.onTestFailed(test
);
129 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
132 public void testOnTestFinished() {
133 final SMTestProxy test
= createTestProxy("some_test", myTestsRootNode
);
135 myResultsViewer
.onTestStarted(test
);
136 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
138 myResultsViewer
.onTestFinished(test
);
139 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
142 public void testOnTestsCountInSuite() {
143 myResultsViewer
.onTestsCountInSuite(200);
145 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
146 assertEquals(200, myResultsViewer
.getTestsTotal());
148 myResultsViewer
.onTestsCountInSuite(50);
149 assertEquals(250, myResultsViewer
.getTestsTotal());
152 public void testOnTestStart_ChangeTotal() {
153 myResultsViewer
.onTestsCountInSuite(2);
155 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
156 assertEquals(2, myResultsViewer
.getTestsTotal());
157 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
158 assertEquals(2, myResultsViewer
.getTestsTotal());
159 myResultsViewer
.onTestStarted(createTestProxy("some_test3", myTestsRootNode
));
160 assertEquals(3, myResultsViewer
.getTestsTotal());
161 myResultsViewer
.onTestStarted(createTestProxy("some_test4", myTestsRootNode
));
162 assertEquals(4, myResultsViewer
.getTestsTotal());
164 myResultsViewer
.onTestsCountInSuite(2);
165 myResultsViewer
.onTestStarted(createTestProxy("another_test1", myTestsRootNode
));
166 assertEquals(6, myResultsViewer
.getTestsTotal());
167 myResultsViewer
.onTestStarted(createTestProxy("another_test2", myTestsRootNode
));
168 assertEquals(6, myResultsViewer
.getTestsTotal());
169 myResultsViewer
.onTestStarted(createTestProxy("another_test3", myTestsRootNode
));
170 assertEquals(7, myResultsViewer
.getTestsTotal());
173 public void testOnFinishTesting_EndTime() {
174 myResultsViewer
.onTestingFinished(myTestsRootNode
);
175 assertTrue(myResultsViewer
.getEndTime() > 0);
178 public void testOnSuiteStarted() {
179 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
180 myResultsViewer
.onSuiteStarted(createSuiteProxy(myTestsRootNode
));
181 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
184 public void testChangeSelectionAction() {
185 final Marker onSelectedHappend
= new Marker();
186 final Ref
<SMTestProxy
> proxyRef
= new Ref
<SMTestProxy
>();
187 final Ref
<Boolean
> focusRequestedRef
= new Ref
<Boolean
>();
189 myResultsViewer
.setShowStatisticForProxyHandler(new PropagateSelectionHandler() {
190 public void handlePropagateSelectionRequest(@Nullable final SMTestProxy selectedTestProxy
, @NotNull final Object sender
,
191 final boolean requestFocus
) {
192 onSelectedHappend
.set();
193 proxyRef
.set(selectedTestProxy
);
194 focusRequestedRef
.set(requestFocus
);
198 final SMTestProxy suite
= createSuiteProxy("suite", myTestsRootNode
);
199 final SMTestProxy test
= createTestProxy("test", myTestsRootNode
);
200 myResultsViewer
.onSuiteStarted(suite
);
201 myResultsViewer
.onTestStarted(test
);
204 myResultsViewer
.selectAndNotify(test
);
205 myResultsViewer
.showStatisticsForSelectedProxy();
206 assertTrue(onSelectedHappend
.isSet());
207 assertEquals(test
, proxyRef
.get());
208 assertTrue(focusRequestedRef
.get());
212 onSelectedHappend
.reset();
214 focusRequestedRef
.set(null);
216 myResultsViewer
.selectAndNotify(suite
);
217 myResultsViewer
.showStatisticsForSelectedProxy();
218 assertTrue(onSelectedHappend
.isSet());
219 assertEquals(suite
, proxyRef
.get());
220 assertTrue(focusRequestedRef
.get());
223 public void testRuby_1767() throws InterruptedException
{
224 TestConsoleProperties
.HIDE_PASSED_TESTS
.set(myConsoleProperties
, true);
226 myEventsProcessor
.onStartTesting();
227 myEventsProcessor
.onSuiteStarted("suite", null);
228 myResultsViewer
.performUpdate();
230 myEventsProcessor
.onTestStarted("test_failed", null);
231 myResultsViewer
.performUpdate();
232 myEventsProcessor
.onTestFailure("test_failed", "", "", false);
233 myResultsViewer
.performUpdate();
234 myEventsProcessor
.onTestFinished("test_failed", 10);
235 myResultsViewer
.performUpdate();
237 myEventsProcessor
.onTestStarted("test", null);
238 myResultsViewer
.performUpdate();
239 assertEquals(2, myTreeModel
.getChildCount(myTreeModel
.getChild(myTreeModel
.getRoot(), 0)));
241 myEventsProcessor
.onTestFinished("test", 10);
242 assertEquals(2, myTreeModel
.getChildCount(myTreeModel
.getChild(myTreeModel
.getRoot(), 0)));
244 myEventsProcessor
.onSuiteFinished("suite");
245 myEventsProcessor
.onFinishTesting();
247 assertEquals(1, myTreeModel
.getChildCount(myTreeModel
.getChild(myTreeModel
.getRoot(), 0)));
250 public void testExpandIfOnlyOneRootChild() throws InterruptedException
{
251 myEventsProcessor
.onStartTesting();
252 myEventsProcessor
.onSuiteStarted("suite1", null);
253 myResultsViewer
.performUpdate();
254 myEventsProcessor
.onSuiteStarted("suite2", null);
255 myResultsViewer
.performUpdate();
257 myEventsProcessor
.onTestStarted("test_failed", null);
258 myResultsViewer
.performUpdate();
259 myEventsProcessor
.onTestFailure("test_failed", "", "", false);
260 myResultsViewer
.performUpdate();
261 myEventsProcessor
.onTestFinished("test_failed", 10);
262 myResultsViewer
.performUpdate();
264 myEventsProcessor
.onTestStarted("test", null);
265 myResultsViewer
.performUpdate();
267 myEventsProcessor
.onTestFinished("test", 10);
268 myResultsViewer
.performUpdate();
270 myEventsProcessor
.onSuiteFinished("suite2");
271 myResultsViewer
.performUpdate();
272 myEventsProcessor
.onSuiteFinished("suite1");
273 myResultsViewer
.performUpdate();
274 myEventsProcessor
.onFinishTesting();
275 myResultsViewer
.performUpdate();
277 final DefaultMutableTreeNode suite1Node
=
278 (DefaultMutableTreeNode
)myTreeModel
.getChild(myTreeModel
.getRoot(), 0);
279 final DefaultMutableTreeNode suite2Node
=
280 (DefaultMutableTreeNode
)myTreeModel
.getChild(suite1Node
, 0);
282 assertTrue(myResultsViewer
.getTreeView().isExpanded(new TreePath(suite1Node
.getPath())));
283 assertFalse(myResultsViewer
.getTreeView().isExpanded(new TreePath(suite2Node
.getPath())));
286 public void testCustomProgress_General() {
287 myResultsViewer
.onCustomProgressTestsCategory("foo", 4);
289 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
290 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
291 myResultsViewer
.onCustomProgressTestStarted();
292 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
294 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
295 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
296 myResultsViewer
.onCustomProgressTestStarted();
297 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
300 public void testCustomProgress_MixedMde() {
301 // enable custom mode
302 myResultsViewer
.onCustomProgressTestsCategory("foo", 4);
304 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
305 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
306 myResultsViewer
.onCustomProgressTestStarted();
307 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
309 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
310 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
311 myResultsViewer
.onCustomProgressTestStarted();
312 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
314 // disable custom mode
315 myResultsViewer
.onCustomProgressTestsCategory(null, 0);
317 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
318 myResultsViewer
.onCustomProgressTestStarted();
319 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
320 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
321 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
323 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
324 myResultsViewer
.onCustomProgressTestStarted();
325 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
326 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
327 assertEquals(4, myResultsViewer
.getTestsCurrentCount());
330 public void testCustomProgress_Failure() {
331 myResultsViewer
.onCustomProgressTestsCategory("foo", 4);
333 final SMTestProxy test1
= createTestProxy("some_test1", myTestsRootNode
);
334 myResultsViewer
.onTestStarted(test1
);
335 myResultsViewer
.onCustomProgressTestStarted();
337 myResultsViewer
.onTestFailed(test1
);
338 assertEquals(0, myResultsViewer
.getTestsFailuresCount());
340 myResultsViewer
.onCustomProgressTestFailed();
341 assertEquals(1, myResultsViewer
.getTestsFailuresCount());
343 assertEquals(ColorProgressBar
.RED
, myResultsViewer
.getTestsStatusColor());
346 public void testCustomProgress_Terminated() {
347 myResultsViewer
.onTestingStarted(myTestsRootNode
);
349 final SMTestProxy test1
= createTestProxy("some_test1", myTestsRootNode
);
350 myResultsViewer
.onTestStarted(test1
);
352 myResultsViewer
.onTestingFinished(myTestsRootNode
);
354 assertEquals(ColorProgressBar
.GREEN
, myResultsViewer
.getTestsStatusColor());
357 public void testCustomProgress_NotRun() {
358 myResultsViewer
.onTestingStarted(myTestsRootNode
);
359 myResultsViewer
.onTestingFinished(myTestsRootNode
);
361 assertEquals(ColorProgressBar
.RED
, myResultsViewer
.getTestsStatusColor());
364 public void testCustomProgress_UnSetCount() {
365 myResultsViewer
.onCustomProgressTestsCategory("foo", 0);
367 assertEquals(0, myResultsViewer
.getTestsTotal());
369 myResultsViewer
.onCustomProgressTestStarted();
370 assertEquals(0, myResultsViewer
.getTestsTotal());
372 myResultsViewer
.onCustomProgressTestStarted();
373 assertEquals(0, myResultsViewer
.getTestsTotal());
375 // count will be updated only on tests finished if wasn't set
376 myResultsViewer
.onTestingFinished(myTestsRootNode
);
377 assertEquals(2, myResultsViewer
.getTestsTotal());
380 public void testCustomProgress_IncreaseCount() {
381 myResultsViewer
.onCustomProgressTestsCategory("foo", 1);
383 assertEquals(1, myResultsViewer
.getTestsTotal());
385 myResultsViewer
.onCustomProgressTestStarted();
386 assertEquals(1, myResultsViewer
.getTestsTotal());
388 myResultsViewer
.onCustomProgressTestStarted();
389 assertEquals(2, myResultsViewer
.getTestsTotal());
392 public void testCustomProgress_IncreaseCount_MixedMode() {
394 myResultsViewer
.onCustomProgressTestsCategory("foo", 1);
396 assertEquals(1, myResultsViewer
.getTestsTotal());
398 myResultsViewer
.onCustomProgressTestStarted();
399 assertEquals(1, myResultsViewer
.getTestsTotal());
401 myResultsViewer
.onCustomProgressTestStarted();
402 assertEquals(2, myResultsViewer
.getTestsTotal());
404 // disable custom mode
405 myResultsViewer
.onCustomProgressTestsCategory(null, 0);
406 assertEquals(2, myResultsViewer
.getTestsTotal());
408 myResultsViewer
.onTestsCountInSuite(1);
409 assertEquals(3, myResultsViewer
.getTestsTotal());
411 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
412 assertEquals(3, myResultsViewer
.getTestsTotal());
414 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
415 assertEquals(4, myResultsViewer
.getTestsTotal());
418 //TODO categories - mized
420 public void testCustomProgress_MentionedCategories_CategoryWithoutName() {
421 // enable custom mode
422 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
424 myResultsViewer
.onCustomProgressTestsCategory("foo", 4);
426 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
429 public void testCustomProgress_MentionedCategories_DefaultCategory() {
430 // enable custom mode
431 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
433 myResultsViewer
.onCustomProgressTestStarted();
435 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
438 public void testCustomProgress_MentionedCategories_OneCustomCategory() {
439 // enable custom mode
440 myResultsViewer
.onCustomProgressTestsCategory("Foo", 4);
441 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
443 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
444 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
446 myResultsViewer
.onCustomProgressTestStarted();
447 assertSameElements(myResultsViewer
.getMentionedCategories(), "Foo");
449 // disable custom mode
450 myResultsViewer
.onCustomProgressTestsCategory(null, 0);
451 assertSameElements(myResultsViewer
.getMentionedCategories(), "Foo");
454 public void testCustomProgress_MentionedCategories_SeveralCategories() {
455 // enable custom mode
456 myResultsViewer
.onCustomProgressTestsCategory("Foo", 4);
457 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
459 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
460 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
462 myResultsViewer
.onCustomProgressTestStarted();
463 assertSameElements(myResultsViewer
.getMentionedCategories(), "Foo");
465 // disable custom mode
466 myResultsViewer
.onCustomProgressTestsCategory(null, 0);
468 myResultsViewer
.onCustomProgressTestStarted();
469 assertSameElements(myResultsViewer
.getMentionedCategories(), "Foo");
471 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
472 assertSameElements(myResultsViewer
.getMentionedCategories(), "Foo", TestsPresentationUtil
.DEFAULT_TESTS_CATEGORY
);
475 public void testCustomProgress_MentionedCategories() {
476 // enable custom mode
477 assertTrue(myResultsViewer
.getMentionedCategories().isEmpty());
479 myResultsViewer
.onCustomProgressTestsCategory("foo", 4);
481 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
482 assertEquals(0, myResultsViewer
.getTestsCurrentCount());
483 myResultsViewer
.onCustomProgressTestStarted();
484 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
486 myResultsViewer
.onTestStarted(createTestProxy("some_test2", myTestsRootNode
));
487 assertEquals(1, myResultsViewer
.getTestsCurrentCount());
488 myResultsViewer
.onCustomProgressTestStarted();
489 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
491 // disable custom mode
492 myResultsViewer
.onCustomProgressTestsCategory(null, 0);
494 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
495 myResultsViewer
.onCustomProgressTestStarted();
496 assertEquals(2, myResultsViewer
.getTestsCurrentCount());
497 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
498 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
500 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
501 myResultsViewer
.onCustomProgressTestStarted();
502 assertEquals(3, myResultsViewer
.getTestsCurrentCount());
503 myResultsViewer
.onTestStarted(createTestProxy("some_test1", myTestsRootNode
));
504 assertEquals(4, myResultsViewer
.getTestsCurrentCount());