Skip to content

Inject into test case from launcher #3786

Open

Description

I would like to inject a test class’ field from my launcher before executing the test. IIUC, this is currently impossible. This feature request documents the reason I (think that I) need this.

Overview

I develop a software to grade student’s work. The teacher would write a unit test then run my software. My software would download student 1’s work, compile it on the fly, execute the teacher test on the student 1 work, grade it; download student 2’s work, compile it on the fly, execute the teacher test on the student 2 work, grade it; and so on for each students; and then return a list of all grades to the user.

More details

The teacher would ask students to implement an interface that she provides, say, Additioner.
The teacher would write a unit test class that has a field Additioner studentAdditioner and test methods that use that field.
My software compiles student 1’s class, say, MyAdditioner, that implements Additioner, and should inject an instance of that class into the field studentAdditioner so that the teacher unit test will run on the student 1 instance.

Missing

My software is able to use JUnit’s API to launch the teacher test, but is unable to inject the student instance into the test field. Note that such injection must happen in the context that creates the launcher, not in the context of the junit test, as the test is started by my software.

Workaround

As suggested in the linked threads, one could use JNDI or other external means of communicating an instance, but this would introduce unnecessary complexity and probably be non-transparent to my users (i.e., the teacher).

Sorry if I misunderstood the discussions of the linked threads and it is actually possible, in which case I’d be glad to be directed to some way of proceeding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions