Auto-label containers with test class and field in @Testcontainers extension#11918
Auto-label containers with test class and field in @Testcontainers extension#11918lekhrocks wants to merge 1 commit into
Conversation
…tension Before starting a container via @testcontainers, the JUnit extension now sets two identifying labels on the container: ``` testcontainers/test-class -> "com.example.MyPostgresTest" testcontainers/test-field -> "postgresContainer" ``` This lets users identify which container belongs to which test at a glance: ``` docker ps --filter label=testcontainers/test-class=com.example.MyPostgresTest ``` And trace CI failures back to the owning test from container metadata.
|
Can we please discuss the ideas before raising a PR? |
Makes sense! I should have started with a discussion first. I've opened one here: #11919. Happy to iterate on the approach based on maintainer feedback before reopening the PR. |
|
Thanks for your contribution. Two things:
I think this is useful information, in the past thought about it as well but didn't dig deeper into the second item. I also thought about an specific section in the JUnit report. For now, I would avoid having different ways to create a container. |
@eddumelendez
I think a better approach would be something in the JUnit report layer, a test execution listener that captures container IDs and maps them to test class/method in the report output. That way it works uniformly regardless of how containers are created. I'd be happy to explore that direction in a future contribution. Thanks again for the feedback. |
Closes #11919
Before starting a container via
@Testcontainers, the JUnit extension now sets two identifying labels on the container:This lets users identify which container belongs to which test at a glance:
And trace CI failures back to the owning test from container metadata.