Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @BeforeAll as a non-jvmstatic so I can get bean values #1053

Open
tgkprog opened this issue Jul 5, 2024 · 3 comments
Open

Implement @BeforeAll as a non-jvmstatic so I can get bean values #1053

tgkprog opened this issue Jul 5, 2024 · 3 comments

Comments

@tgkprog
Copy link

tgkprog commented Jul 5, 2024

Feature description

We want to run a docker with an instance of my database running in it. The data base needs some config that is in my application.yaml - even for local run.

We rather not hard code that information or make another file to load at run time.
Would be good if Micronaut added this to their backlog, to add "@beforeeach" support as a regular method in "@MicronautTest" Right now need to implement it in:


@MicronautTest
@Requires(property = "MICRONAUT_ENVIRONMENTS", value = "localTest")
@Suite
@SelectClasses(
    AaLocalTestSuiteWithDocker::class,
    ArtControllerTests::class,
    HistoryControllerTest::class
)
class AaLocalTestSuiteWithDocker
    (
    private val dynamoDbTableCreator: DynamoDbTableCreator,
    private val dynanamoConfiguration: DynamoConfiguration,
    private val dynamoDbClient: DynamoDbClient
) {
...
companion object {

        @BeforeAll
        @JvmStatic
        fun beforeAll2(){
            logger.info("beforeAll2")
        }
        ...
}

Right now I keep a private var haveRunBeforeAllTests: Boolean = false
then a "@beforeeach" and check if this has run before

@BeforeEach
    fun beforeEachWithCheckForOnce() {
        logger.info("beforeEachWithCheckForOnce")

        if (haveRunBeforeAllTests) return
        haveRunBeforeAllTests = true
        logger.info("Executing setup tasks before each test")
        LocalStackSetup.setup()    

@graemerocher
Copy link
Contributor

can you not simply add method arguments to beforeAll2 with the beans you need?

@tgkprog
Copy link
Author

tgkprog commented Jul 6, 2024

No, they are not initialised by Micronaut at that time, they are Micronaut beans

@graemerocher
Copy link
Contributor

that is what I mean, you can inject beans into JUnit 5 method arguments

@graemerocher graemerocher transferred this issue from micronaut-projects/micronaut-core Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants