{"id":19968210,"url":"https://github.com/sormuras/brahms","last_synced_at":"2025-07-08T00:17:43.296Z","repository":{"id":57730974,"uuid":"140681993","full_name":"sormuras/brahms","owner":"sormuras","description":"JUnit 5 Extension and TestEngine ideas","archived":false,"fork":false,"pushed_at":"2019-02-06T10:06:50.000Z","size":255,"stargazers_count":10,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-04T01:31:55.797Z","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/sormuras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-12T08:06:25.000Z","updated_at":"2021-07-11T08:54:53.000Z","dependencies_parsed_at":"2022-09-26T22:01:38.261Z","dependency_job_id":null,"html_url":"https://github.com/sormuras/brahms","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/sormuras/brahms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fbrahms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fbrahms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fbrahms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fbrahms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sormuras","download_url":"https://codeload.github.com/sormuras/brahms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fbrahms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261695414,"owners_count":23195743,"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-11-13T02:44:52.890Z","updated_at":"2025-06-24T14:40:04.847Z","avatar_url":"https://github.com/sormuras.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# brahms\n\n[![jdk11](https://img.shields.io/badge/jdk-11-blue.svg)](http://jdk.java.net/11)\n[![travis](https://travis-ci.com/sormuras/brahms.svg?branch=master)](https://travis-ci.com/sormuras/brahms)\n[![Maven Central](https://img.shields.io/maven-central/v/de.sormuras/brahms.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22de.sormuras%22%20AND%20a:%22brahms%22)\n\nThis projects offers some proof-of-concept ideas implementing JUnit Jupiter's Extension API and JUnit Platform's\n[TestEngine](https://junit.org/junit5/docs/current/user-guide/#launcher-api-engines-custom):\n\n![Brahms Overview](docs/brahms-overview.png)\n\nDownload the [latest JAR](https://search.maven.org/remote_content?g=de.sormuras\u0026a=brahms\u0026v=LATEST) or depend via Maven:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ede.sormuras\u003c/groupId\u003e\n  \u003cartifactId\u003ebrahms\u003c/artifactId\u003e\n  \u003cversion\u003e{brahms.version}\u003c/version\u003e\n  \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nor Gradle:\n\n```\ntestCompile \"de.sormuras:brahms:${brahms.version}\"\n```\n\nDon't want to use the brahms API in your test code?\nAdd a test runtime dependency will do just fine:\n\n```\ntestRuntime \"de.sormuras:brahms:${brahms.version}\"\n```\n\n## Resource Manager Extension\n\nThe resource manager extension provides hassle-free global, named, and \"one-shot\" resource management.\nYou may use three different annotations at method parameters to declare in which mode a resource should be managed.\n\n- `ResourceManager.@New` - create an instance of the resource and close it when the context is teared down.\n- `ResourceManager.@Shared` - get or create an instance of the named resource\n- `ResourceManager.@Singleton` - get or create the single instance of the resource - same as `@Shared(name = type.name()...)` \n\n`@Shared` and `@Singleton` resource are created on demand - the first parameter resolution request wins.\nResource created be those annotation may be used and shared between different test classes!\nThe attached resources are closed when the global Jupiter extension context store is closing.\n\n### Temporary Directory as Resource\n\nBrahms provides `Temporary` as a resource supplier that creates and closes temporary directories.\n\n```java\n@ExtendWith(ResourceManager.class)\nclass Tests { \n  @Test\n  void test(@New(Temporary) Path temp) {\n\t// do something with \"temp\"\n  }\n}\n```\n\n`@New` resources supplied to the constructor of a test class are automatically cleaned up after the \n```java\n@ExtendWith(ResourceManager.class)\nclass Tests {\n\n  final Path temp;\t\t\n\t\n  Tests(@New(Temporary) Path temp) {\n\tthis.temp = temp;\n  }\n  \n  @Test\n  void test() {\n\t// do something with \"this.temp\"\n  }\n}\n```\n\nUse `@TempDir`, a composed annotation short-cut for `@ResourceManager.New(Temporary.class)`:\n\n```java\n@ExtendWith(ResourceManager.class)\nclass Tests { \n  @Test\n  void test(@TempDir Path temp) {\n\t// do something with \"temp\"\n  }\n}\n```\n\n\n### Custom Resource\n\nFind samples of custom resources, like a declaring and sharing a `WebServer` and temporary \u0026 in-memory directory via `JimFS`, here:\n\n[integration/resource](https://github.com/sormuras/brahms/tree/master/src/test/java/integration/resource)\n\n## ☕ Brahms Maingine\n\n**NOTE: Development of Maingine is continued here: https://github.com/sormuras/mainrunner**\n\nFind classes that contain a `public static void main(String[] args)` method\nand execute them.\n\n#### Plain\n\nA simple main class will be executed in-process and any exception will cause\nthe test to be marked as failed.\n\n```java\npublic class MainPlain {\n  public static void main(String... args) {\n    // ...\n  }\n}\n```\n\n#### Customize `@Main` execution\n\nUse the `@Main` annotation to customize the execution: pass arguments, set a\ndisplay name, fork a `java` process with different VM parameters. Any exception\nwill cause the test to be marked as failed.\n\n```java\npublic class MainTests {\n  // No-args test run\n  @Main\n\n  // Single argument test run\n  @Main(\"1\")\n\n  // Multiple arguments test run\n  @Main({\"2\", \"3\"})\n\n  // Custom display name of test run\n  @Main(\n      displayName = \"main with '${ARGS}' as args\",\n      value = {\"3\", \"4\", \"5\"})\n\n  // Fork VM and launch with specific java/VM options\n  @Main(\n      displayName = \"☕ ${ARGS}\",\n      value = {\"6\", \"7\"},\n      java = @Java(options = {\"-classpath\", \"${java.class.path}\"}))\n\n  public static void main(String... args) {\n    var message = args.length == 0 ? \"\u003cno-args\u003e\" : String.join(\", \", args);\n    System.out.println(\"MainTests: \" + message);\n  }\n}\n```\n\nWhen forking, you may also expect a non-zero exit value:\n\n```java\npublic class SystemExit123 {\n\n  @Main(\n  \tvalue = \"123\",\n  \tjava = @Java(expectedExitValue = 123, options = {\"-classpath\", \"${java.class.path}\"}))              \n  public static void main(String... args) {\n    System.exit(Integer.parseInt(args[0]));\n  }\n}\n```\n\n## 📜 Brahms Single File Source Code TestEngine\n\n**NOTE: Development of SingleFileSourceCodeTestEngine is continued here: https://github.com/sormuras/mainrunner**\n\nFind `.java` source files that contain a `public static void main(String[] args)` method\nand execute them. For details see [JEP 330](http://openjdk.java.net/jeps/330).\n\n```java\nclass SingleFileSourceCodeProgram {\n  public static void main(String... args) {\n    // ...\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormuras%2Fbrahms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsormuras%2Fbrahms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormuras%2Fbrahms/lists"}