Search in sources :

Example 1 with TestStateStorage

use of com.intellij.execution.TestStateStorage in project intellij-community by JetBrains.

the class ShowRecentTests method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    UsageTrigger.trigger(ID);
    final TestStateStorage testStorage = TestStateStorage.getInstance(project);
    final TestLocator testLocator = new TestLocator(project);
    final RecentTestRunnerImpl testRunner = new RecentTestRunnerImpl(project, testLocator);
    final Map<String, TestStateStorage.Record> records = testStorage.getRecentTests(TEST_LIMIT, getSinceDate());
    RunConfigurationByRecordProvider configurationProvider = new RunConfigurationByRecordProvider(project);
    RecentTestsListProvider listProvider = new RecentTestsListProvider(configurationProvider, records);
    List<RecentTestsPopupEntry> entries = listProvider.getTestsToShow();
    SelectTestStep selectStepTest = new SelectTestStep("Debug Recent Tests", entries, testRunner);
    RecentTestsListPopup popup = new RecentTestsListPopup(selectStepTest, testRunner, testLocator);
    popup.showCenteredInCurrentWindow(project);
    cleanDeadTests(entries, testLocator, testStorage);
}
Also used : TestStateStorage(com.intellij.execution.TestStateStorage) Project(com.intellij.openapi.project.Project)

Example 2 with TestStateStorage

use of com.intellij.execution.TestStateStorage in project intellij-community by JetBrains.

the class RunLineMarkerTest method testNestedTestClass.

public void testNestedTestClass() throws Exception {
    TestStateStorage stateStorage = TestStateStorage.getInstance(getProject());
    String testUrl = "java:suite://Main$MainTest";
    try {
        stateStorage.writeState(testUrl, new TestStateStorage.Record(TestStateInfo.Magnitude.FAILED_INDEX.getValue(), new Date(), 0));
        myFixture.addClass("package junit.framework; public class TestCase {}");
        PsiFile file = myFixture.configureByText("MainTest.java", "public class Main {\n" + "  public class Main<caret>Test extends junit.framework.TestCase {\n" + "    public void testFoo() {\n" + "    }\n" + "  }" + "}");
        RunLineMarkerContributor.Info info = new TestRunLineMarkerProvider().getInfo(file.findElementAt(myFixture.getCaretOffset()));
        assertNotNull(info);
        assertEquals(AllIcons.RunConfigurations.TestState.Red2, info.icon);
    } finally {
        stateStorage.removeState(testUrl);
    }
}
Also used : TestStateStorage(com.intellij.execution.TestStateStorage) RunLineMarkerContributor(com.intellij.execution.lineMarker.RunLineMarkerContributor) TestRunLineMarkerProvider(com.intellij.testIntegration.TestRunLineMarkerProvider) PsiFile(com.intellij.psi.PsiFile) Date(java.util.Date)

Example 3 with TestStateStorage

use of com.intellij.execution.TestStateStorage in project flutter-intellij by flutter.

the class FlutterTestLineMarkerContributor method getTestStateIcon.

@NotNull
private static Icon getTestStateIcon(@NotNull PsiElement element, @NotNull Icon defaultIcon) {
    // SMTTestProxy maps test run data to a URI derived from a location hint produced by `package:test`.
    // If we can find corresponding data, we can provide state-aware icons. If not, we default to
    // a standard Run state.
    PsiFile containingFile;
    try {
        containingFile = element.getContainingFile();
    } catch (PsiInvalidElementAccessException e) {
        containingFile = null;
    }
    final Project project = element.getProject();
    final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    final Document document = containingFile == null ? null : psiDocumentManager.getDocument(containingFile);
    if (document != null) {
        final int textOffset = element.getTextOffset();
        final int lineNumber = document.getLineNumber(textOffset);
        // e.g., dart_location:///Users/pq/IdeaProjects/untitled1298891289891/test/unit_test.dart,3,2,["my first unit test"]
        final String path = containingFile.getVirtualFile().getPath();
        final String testLocationPrefix = "dart_location://" + path + "," + lineNumber;
        final TestStateStorage storage = TestStateStorage.getInstance(project);
        if (storage != null) {
            final Map<String, TestStateStorage.Record> tests = storage.getRecentTests(SCANNED_TEST_RESULT_LIMIT, getSinceDate());
            if (tests != null) {
                // TODO(pq): investigate performance implications.
                for (Map.Entry<String, TestStateStorage.Record> entry : tests.entrySet()) {
                    if (entry.getKey().startsWith(testLocationPrefix)) {
                        final TestStateStorage.Record state = entry.getValue();
                        final TestStateInfo.Magnitude magnitude = TestIconMapper.getMagnitude(state.magnitude);
                        if (magnitude != null) {
                            switch(magnitude) {
                                case IGNORED_INDEX:
                                    return AllIcons.RunConfigurations.TestState.Yellow2;
                                case ERROR_INDEX:
                                case FAILED_INDEX:
                                    return AllIcons.RunConfigurations.TestState.Red2;
                                case PASSED_INDEX:
                                case COMPLETE_INDEX:
                                    return AllIcons.RunConfigurations.TestState.Green2;
                                default:
                            }
                        }
                    }
                }
            }
        }
    }
    return defaultIcon;
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) TestStateStorage(com.intellij.execution.TestStateStorage) Document(com.intellij.openapi.editor.Document) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Map(java.util.Map) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TestStateStorage (com.intellij.execution.TestStateStorage)3 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 RunLineMarkerContributor (com.intellij.execution.lineMarker.RunLineMarkerContributor)1 TestStateInfo (com.intellij.execution.testframework.sm.runner.states.TestStateInfo)1 Document (com.intellij.openapi.editor.Document)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiInvalidElementAccessException (com.intellij.psi.PsiInvalidElementAccessException)1 TestRunLineMarkerProvider (com.intellij.testIntegration.TestRunLineMarkerProvider)1 Date (java.util.Date)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1