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

Add JUnit support #107

Closed
wants to merge 13 commits into from
Closed

Add JUnit support #107

wants to merge 13 commits into from

Conversation

Matyrobbrt
Copy link
Member

Add support for configuring JUnit run tasks.

@Matyrobbrt Matyrobbrt added the enhancement New feature or request label Jan 24, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Jan 24, 2024

  • Publish PR to GitHub Packages

Last commit published: 0363b2c51f628e061a5232e364164142101d05f2.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #107' // https://github.com/neoforged/NeoGradle/pull/107
        url 'https://prmaven.neoforged.net/NeoGradle/pr107'
        content {
            includeModule('net.neoforged.gradle', 'dsl-vanilla')
            includeModule('net.neoforged.gradle', 'utils')
            includeModule('net.neoforged.gradle', 'dsl-mixin')
            includeModule('net.neoforged.gradle', 'common')
            includeModule('net.neoforged.gradle', 'junit')
            includeModule('net.neoforged.gradle', 'dsl-platform')
            includeModule('net.neoforged.gradle', 'dsl-userdev')
            includeModule('net.neoforged.gradle', 'mixin')
            includeModule('net.neoforged.gradle.mixin', 'net.neoforged.gradle.mixin.gradle.plugin')
            includeModule('net.neoforged.gradle', 'dsl-neoform')
            includeModule('net.neoforged.gradle.common', 'net.neoforged.gradle.common.gradle.plugin')
            includeModule('net.neoforged.gradle', 'neoform')
            includeModule('net.neoforged.gradle.neoform', 'net.neoforged.gradle.neoform.gradle.plugin')
            includeModule('net.neoforged.gradle', 'dsl-common')
            includeModule('net.neoforged.gradle.junit', 'net.neoforged.gradle.junit.gradle.plugin')
            includeModule('net.neoforged.gradle.userdev', 'net.neoforged.gradle.userdev.gradle.plugin')
            includeModule('net.neoforged.gradle', 'vanilla')
            includeModule('net.neoforged.gradle', 'platform')
            includeModule('net.neoforged.gradle.platform', 'net.neoforged.gradle.platform.gradle.plugin')
            includeModule('net.neoforged.gradle', 'userdev')
            includeModule('net.neoforged.gradle.vanilla', 'net.neoforged.gradle.vanilla.gradle.plugin')
        }
    }
}

@SquidDev
Copy link
Contributor

How does this interact with running tests from IDEA directly (rather than through Gradle)? I'm assuming that it won't work, as FML/BootstrapLauncher expect environment variables and system properties to be present?

@Matyrobbrt
Copy link
Member Author

If you run tests with the Gradle runner it will work fine in IDEA, if you run with the IntelliJ runner it won't, that's correct, and that's not really fixable.

@SquidDev
Copy link
Contributor

That's useful to know, thanks! Mostly just trying to compare with what I have now (I only need MC's Bootstrap for my existing tests, so can get away with doing less of a thorough job :)).

}
}

RunImpl junitRun = getOrCreateRun("junitTest", project, runtimeDefinition, runType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No if the user does not create one, then you should abort processing.
The userdev runtime will create a run named after the runtype, so creating another run here is redundant and wrong anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user is explicitly applying a special Neogradle junit plugin to get junit tests to work. That should get that set up without surprises and as seamlessly as possible, in my opinion.

Also: I do not think the userdev runtime creates runs based on runtypes automatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not create them automatically. And even if it did, that would be a bad idea for the junit run type (and so would the user creating it normally). The run would generate run* tasks, prepare* tasks, and IDE run configurations which wouldn't work with JUnit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it does not create the runs automatically. But your runtype should be configured enough that it should only need a:

runs {
   unitTests{} //Or what ever the name of the unit test run type is.
}

To get the plugin to work. That is how all other run types are designed.
Please redesign this area.

}
}

RunImpl junitRun = getOrCreateRun("junitTest", project, runtimeDefinition, runType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it does not create the runs automatically. But your runtype should be configured enough that it should only need a:

runs {
   unitTests{} //Or what ever the name of the unit test run type is.
}

To get the plugin to work. That is how all other run types are designed.
Please redesign this area.

@shartte
Copy link
Contributor

shartte commented Feb 20, 2024

@marchermans The IntelliJ & Gradle unit test launchers are not runTypes, hence the comparison falls flat. We do not launch via a generated gradle task, nor do we launch via BootstrapLauncher here.
I don't want to expose these internal shenanigans for users since it's more friction to get unit tests to work and not less.

@marchermans
Copy link
Contributor

Is superseded by #183

@Matyrobbrt Matyrobbrt deleted the junit branch May 26, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants