Search in sources :

Example 6 with MockPrinter

use of com.intellij.execution.testframework.sm.runner.ui.MockPrinter in project intellij-community by JetBrains.

the class SMTRunnerConsoleTest method testProcessor_OnFailure.

public void testProcessor_OnFailure() {
    final SMTestProxy myTest1 = startTestWithPrinter("my_test");
    myEventsProcessor.onTestFailure(new TestFailedEvent("my_test", "error msg", "method1:1\nmethod2:2", false, null, null));
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test", "stdout1 ", true));
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test", "stderr1 ", false));
    assertAllOutputs(myMockResettablePrinter, "stdout1 ", "\nerror msg\nmethod1:1\nmethod2:2\nstderr1 ", "");
    final MockPrinter mockPrinter1 = new MockPrinter(true);
    mockPrinter1.onNewAvailable(myTest1);
    assertAllOutputs(mockPrinter1, "stdout1 ", "stderr1 \nerror msg\nmethod1:1\nmethod2:2\n", "");
    //other output order
    final SMTestProxy myTest2 = startTestWithPrinter("my_test2");
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test2", "stdout1 ", true));
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test2", "stderr1 ", false));
    myEventsProcessor.onTestFailure(new TestFailedEvent("my_test2", "error msg", "method1:1\nmethod2:2", false, null, null));
    assertAllOutputs(myMockResettablePrinter, "stdout1 ", "stderr1 \nerror msg\nmethod1:1\nmethod2:2\n", "");
    final MockPrinter mockPrinter2 = new MockPrinter(true);
    mockPrinter2.onNewAvailable(myTest2);
    assertAllOutputs(mockPrinter2, "stdout1 ", "stderr1 \nerror msg\nmethod1:1\nmethod2:2\n", "");
}
Also used : MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter)

Example 7 with MockPrinter

use of com.intellij.execution.testframework.sm.runner.ui.MockPrinter in project intellij-community by JetBrains.

the class SMTRunnerConsoleTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final TestConsoleProperties consoleProperties = createConsoleProperties();
    final ExecutionEnvironment environment = new ExecutionEnvironment();
    myMockResettablePrinter = new MockPrinter(true);
    myConsole = new MyConsoleView(consoleProperties, environment);
    myConsole.initUI();
    myResultsViewer = myConsole.getResultsViewer();
    myRootSuite = myResultsViewer.getTestsRootNode();
    myEventsProcessor = new GeneralToSMTRunnerEventsConvertor(consoleProperties.getProject(), myResultsViewer.getTestsRootNode(), "SMTestFramework");
    myEventsProcessor.onStartTesting();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter) TestConsoleProperties(com.intellij.execution.testframework.TestConsoleProperties)

Example 8 with MockPrinter

use of com.intellij.execution.testframework.sm.runner.ui.MockPrinter in project intellij-community by JetBrains.

the class SMTRunnerConsoleTest method testProcessor_OnErrorMsg.

public void testProcessor_OnErrorMsg() {
    final SMTestProxy myTest1 = startTestWithPrinter("my_test");
    myEventsProcessor.onError("error msg", "method1:1\nmethod2:2", true);
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test", "stdout1 ", true));
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test", "stderr1 ", false));
    assertAllOutputs(myMockResettablePrinter, "stdout1 ", "\nerror msg\nmethod1:1\nmethod2:2\nstderr1 ", "");
    final MockPrinter mockPrinter1 = new MockPrinter(true);
    mockPrinter1.onNewAvailable(myTest1);
    assertAllOutputs(mockPrinter1, "stdout1 ", "\n" + "error msg\n" + "method1:1\n" + "method2:2\n" + "stderr1 ", "");
    myEventsProcessor.onTestFinished(new TestFinishedEvent("my_test", 1l));
    myTest1.setFinished();
    //other output order
    final SMTestProxy myTest2 = startTestWithPrinter("my_test2");
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test2", "stdout1 ", true));
    myEventsProcessor.onTestOutput(new TestOutputEvent("my_test2", "stderr1 ", false));
    myEventsProcessor.onError("error msg", "method1:1\nmethod2:2", true);
    assertAllOutputs(myMockResettablePrinter, "stdout1 ", "stderr1 \nerror msg\nmethod1:1\nmethod2:2\n", "");
    final MockPrinter mockPrinter2 = new MockPrinter(true);
    mockPrinter2.onNewAvailable(myTest2);
    assertAllOutputs(mockPrinter2, "stdout1 ", "stderr1 \nerror msg\nmethod1:1\nmethod2:2\n", "");
}
Also used : MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter)

Example 9 with MockPrinter

use of com.intellij.execution.testframework.sm.runner.ui.MockPrinter in project intellij-plugins by JetBrains.

the class DartTestEventsConverterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myNodes = new HashMap<>();
    final ExecutionEnvironment environment = new ExecutionEnvironment();
    myMockResettablePrinter = new MockPrinter(true);
    TestConsoleProperties consoleProperties = createConsoleProperties();
    myConsole = new MyConsoleView(consoleProperties, environment);
    myConsole.initUI();
    myResultsViewer = myConsole.getResultsViewer();
    myEventsConverter = new DartTestEventsConverter(DartTestRunningState.DART_FRAMEWORK_NAME, consoleProperties, DartUrlResolver.getInstance(getProject(), getSourceRoot()));
    myEventsProcessor = new DartTestEventsProcessor(consoleProperties.getProject(), DartTestRunningState.DART_FRAMEWORK_NAME);
    myEventsProcessor.addEventsListener(myResultsViewer);
    myEventsConverter.setProcessor(myEventsProcessor);
    myTreeModel = myResultsViewer.getTreeView() == null ? null : (DefaultTreeModel) myResultsViewer.getTreeView().getModel();
    assertNotNull(myTreeModel);
    myParentNode = (DefaultMutableTreeNode) myTreeModel.getRoot();
    myEventsProcessor.onStartTesting();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter) TestConsoleProperties(com.intellij.execution.testframework.TestConsoleProperties)

Example 10 with MockPrinter

use of com.intellij.execution.testframework.sm.runner.ui.MockPrinter in project intellij-community by JetBrains.

the class GeneralToSMTRunnerEventsConvertorTest method testPreserveFullOutputAfterImport.

public void testPreserveFullOutputAfterImport() throws Exception {
    mySuite.addChild(mySimpleTest);
    for (int i = 0; i < 550; i++) {
        String message = "line" + i + "\n";
        mySimpleTest.addLast(printer -> printer.print(message, ConsoleViewContentType.NORMAL_OUTPUT));
    }
    mySimpleTest.setFinished();
    mySuite.setFinished();
    SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
    TransformerHandler handler = transformerFactory.newTransformerHandler();
    handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
    handler.getTransformer().setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    File output = FileUtil.createTempFile("output", "");
    try {
        FileUtilRt.createParentDirs(output);
        handler.setResult(new StreamResult(new FileWriter(output)));
        MockRuntimeConfiguration configuration = new MockRuntimeConfiguration(getProject());
        TestResultsXmlFormatter.execute(mySuite, configuration, new SMTRunnerConsoleProperties(configuration, "framework", new DefaultRunExecutor()), handler);
        String savedText = FileUtil.loadFile(output);
        assertTrue(savedText.split("\n").length > 550);
        myEventsProcessor.onStartTesting();
        ImportedToGeneralTestEventsConverter.parseTestResults(() -> new StringReader(savedText), myEventsProcessor);
        myEventsProcessor.onFinishTesting();
        List<? extends SMTestProxy> children = myResultsViewer.getTestsRootNode().getChildren();
        assertSize(1, children);
        SMTestProxy testProxy = children.get(0);
        MockPrinter mockPrinter = new MockPrinter();
        testProxy.printOn(mockPrinter);
        assertSize(550, mockPrinter.getAllOut().split("\n"));
    } finally {
        FileUtil.delete(output);
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) StreamResult(javax.xml.transform.stream.StreamResult) FileWriter(java.io.FileWriter) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) StringReader(java.io.StringReader) MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter) File(java.io.File) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor)

Aggregations

MockPrinter (com.intellij.execution.testframework.sm.runner.ui.MockPrinter)15 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 TestConsoleProperties (com.intellij.execution.testframework.TestConsoleProperties)3 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 StreamResult (javax.xml.transform.stream.StreamResult)1