{"id":17685206,"url":"https://github.com/hakky54/console-captor","last_synced_at":"2025-04-14T10:10:24.084Z","repository":{"id":46381156,"uuid":"386003514","full_name":"Hakky54/console-captor","owner":"Hakky54","description":"🎯 ConsoleCaptor captures console output for unit and integration testing purposes","archived":false,"fork":false,"pushed_at":"2025-02-10T12:52:48.000Z","size":91,"stargazers_count":30,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T23:23:24.050Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hakky54.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Hakky54"],"open_collective":"hakky54","ko_fi":"hakky54"}},"created_at":"2021-07-14T16:22:15.000Z","updated_at":"2025-02-10T12:52:52.000Z","dependencies_parsed_at":"2024-06-05T05:43:53.360Z","dependency_job_id":"b194a526-7e50-4248-8aab-2413cfccdd84","html_url":"https://github.com/Hakky54/console-captor","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hakky54%2Fconsole-captor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hakky54%2Fconsole-captor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hakky54%2Fconsole-captor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hakky54%2Fconsole-captor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hakky54","download_url":"https://codeload.github.com/Hakky54/console-captor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860218,"owners_count":21173342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-24T10:26:54.428Z","updated_at":"2025-04-14T10:10:24.051Z","avatar_url":"https://github.com/Hakky54.png","language":"Java","readme":"[![Actions Status](https://github.com/Hakky54/console-captor/workflows/Build/badge.svg)](https://github.com/Hakky54/console-captor/actions)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=io.github.hakky54%3Aconsolecaptor\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=io.github.hakky54%3Aconsolecaptor\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n[![JDK Compatibility](https://img.shields.io/badge/JDK_Compatibility-8+-blue.svg)](#)\n[![Kotlin Compatibility](https://img.shields.io/badge/Kotlin_Compatibility-1.5+-blue.svg)](#)\n[![Scala Compatibility](https://img.shields.io/badge/Scala_Compatibility-2.11+-blue.svg)](#)\n[![Android API Compatibility](https://img.shields.io/badge/Android_API_Compatibility-24+-blue.svg)](#)\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=io.github.hakky54%3Aconsolecaptor\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=io.github.hakky54%3Aconsolecaptor\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=io.github.hakky54%3Aconsolecaptor\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n[![Apache2 license](https://img.shields.io/badge/license-Aache2.0-blue.svg)](https://github.com/Hakky54/console-captor/blob/master/LICENSE)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.hakky54/consolecaptor/badge.svg)](https://mvnrepository.com/artifact/io.github.hakky54/consolecaptor)\n[![javadoc](https://javadoc.io/badge2/io.github.hakky54/consolecaptor/javadoc.svg)](https://javadoc.io/doc/io.github.hakky54/consolecaptor)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FHakky54%2Fconsole-captor.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FHakky54%2Fconsole-captor?ref=badge_shield)\n[![Join the chat at https://gitter.im/hakky54/consolecaptor](https://badges.gitter.im/hakky54/consolecaptor.svg)](https://gitter.im/hakky54/consolecaptor?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-white.svg)](https://sonarcloud.io/dashboard?id=io.github.hakky54%3Aconsolecaptor)\n\n# ConsoleCaptor\n\n# Install library with:\n### Install with [maven](https://mvnrepository.com/artifact/io.github.hakky54/consolecaptor)\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.hakky54\u003c/groupId\u003e\n    \u003cartifactId\u003econsolecaptor\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.3\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n### Install with Gradle\n```groovy\ntestImplementation 'io.github.hakky54:consolecaptor:1.0.3'\n```\n### Install with Scala SBT\n```\nlibraryDependencies += \"io.github.hakky54\" % \"consolecaptor\" % \"1.0.3\" % Test\n```\n### Install with Apache Ivy\n```xml\n\u003cdependency org=\"io.github.hakky54\" name=\"consolecaptor\" rev=\"1.0.3\" /\u003e\n```\n\n## Table of contents\n1. [Introduction](#introduction)\n    - [Advantages](#advantages)\n    - [Tested Java versions](#tested-java-versions)\n2. [Usage](#usage)\n    - [Capture Console Output](#capture-console-output)\n    - [Reuse ConsoleCaptor for multiple tests](#initialize-consolecaptor-once-and-reuse-it-during-multiple-tests-with-clearoutput-method-within-the-aftereach-method)\n3. [Contributing](#contributing)\n4. [License](#license)\n\n# Introduction\nHey, hello there 👋 Welcome. I hope you will like this library ❤️\n\nConsoleCaptor is a library which will enable you to easily capture the output of the console for unit testing purposes.\n\nDo you want to capture logs? Please have a look at [LogCaptor](https://github.com/Hakky54/log-captor).\n\n### Advantages\n- No mocking required\n- No custom JUnit extension required\n- Plug \u0026 play\n- Zero transitive dependencies\n\n### Tested Java versions\n- Java 8\n- Java 11+\n\nSee the unit test [ConsoleCaptorShould](src/test/java/nl/altindag/console/ConsoleCaptorShould.java) for all the scenario's.\n\n# Usage\n##### Capture console output\n```java\npublic class FooService {\n\n    public void sayHello() {\n        System.out.println(\"Keyboard not responding. Press any key to continue...\");\n        System.err.println(\"Congratulations, you are pregnant!\");\n    }\n\n}\n```\n###### Unit test:\n\n```java\nimport static org.assertj.core.api.Assertions.assertThat;\n\nimport nl.altindag.console.ConsoleCaptor;\nimport org.junit.jupiter.api.Test;\n\npublic class FooServiceShould {\n\n    @Test\n    public void captureStandardAndErrorOutput() {\n        ConsoleCaptor consoleCaptor = new ConsoleCaptor();\n\n        FooService fooService = new FooService();\n        fooService.sayHello();\n\n        assertThat(consoleCaptor.getStandardOutput()).contains(\"Keyboard not responding. Press any key to continue...\");\n        assertThat(consoleCaptor.getErrorOutput()).contains(\"Congratulations, you are pregnant!\");\n        \n        consoleCaptor.close();\n    }\n}\n```\n\n##### Initialize ConsoleCaptor once and reuse it during multiple tests with clearOutput() method within the afterEach method:\n```java\nimport nl.altindag.console.ConsoleCaptor;\nimport org.junit.jupiter.api.Test;\nimport org.junit.jupiter.api.AfterAll;\nimport org.junit.jupiter.api.AfterEach;\nimport org.junit.jupiter.api.BeforeAll;\n\npublic class FooServiceShould {\n\n    private static ConsoleCaptor consoleCaptor;\n    \n    @BeforeAll\n    public static void setupConsoleCaptor() {\n        consoleCaptor = new ConsoleCaptor();\n    }\n\n    @AfterEach\n    public void clearOutput() {\n        consoleCaptor.clearOutput();\n    }\n    \n    @AfterAll\n    public static void tearDown() {\n        consoleCaptor.close();\n    }\n\n    @Test\n    public void captureStandardOutput() {\n        FooService service = new FooService();\n        service.sayHello();\n\n        assertThat(consoleCaptor.getStandardOutput()).contains(\"Keyboard not responding. Press any key to continue...\");\n    }\n\n    @Test\n    public void captureErrorOutput() {\n        FooService service = new FooService();\n        service.sayHello();\n\n        assertThat(consoleCaptor.getErrorOutput()).contains(\"Congratulations, you are pregnant!\");\n    }\n\n}\n```\n\n# Contributing\n\nThere are plenty of ways to contribute to this project:\n\n* Give it a star\n* Make a donation through [GitHub](https://github.com/sponsors/Hakky54) or [open collective](https://opencollective.com/hakky54)\n* Join the [Gitter room](https://gitter.im/hakky54/consolecaptor) and leave a feedback or help with answering users questions\n* Submit a PR\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FHakky54%2Fconsole-captor.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FHakky54%2Fconsole-captor?ref=badge_large)\n","funding_links":["https://github.com/sponsors/Hakky54","https://opencollective.com/hakky54","https://ko-fi.com/hakky54"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakky54%2Fconsole-captor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhakky54%2Fconsole-captor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakky54%2Fconsole-captor/lists"}