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

Implementing test mod #8

Open
LLytho opened this issue Feb 24, 2022 · 5 comments
Open

Implementing test mod #8

LLytho opened this issue Feb 24, 2022 · 5 comments

Comments

@LLytho
Copy link

LLytho commented Feb 24, 2022

Hey I'm trying to implement a testmod for each fabric and forge.
I tried multiple things now but I run into several problems when I try different things.

Goal is that fabric test sources have access to common test & main sources. Forge test sources should have access to common test & main. And common test has access to main sources.

My tries:

Using testFixtures:

Instead of common test a testFixtures sourceset exists. From the gradle wiki it tells that testFixtures has access to main but they don't have and I could not figure out why.

Dependency to sourceSets example:

adding this to Fabric and Forge gradle:
Sources seems to have access to each other. At least I don't have errors in the IDE.

    testImplementation project(":Common").sourceSets.main.output
    testImplementation project(":Common").sourceSets.test.output

###Runconfig for Fabric:
-> Results into fabric just starts without the test mod loaded.

        testClient {
            client()
            source = sourceSets.test
            setConfigName("Test Minecraft Client")
            ideConfigGenerated(true)
            runDir("../run")
        }

Runconfig for Forge:

--> Crashes because some packages are exported by multiple mods. I assume it's because the mod or the testmod exports the same package? The package names are different. So I don't really understand whats happening here.

        clientTest {
            parent runs.client
            environment 'MOD_CLASSES', 'dummy' // From Forge: FG will replace this but it's needed to run
            mods {
                modClientRun {
                    source sourceSets.main
                    source project(":Common").sourceSets.main
                }
                "${mod_id}_test" {
                    source sourceSets.test
                    source project(":Common").sourceSets.test
                }
            }
        }

When I look into the build folders the resources are correct and the mods have their mods.toml or fabric.mod.json file.

I mostly tried to learn from this and the links they added: https://stackoverflow.com/questions/5644011/multi-project-test-dependencies-with-gradle

And sorry for my english ._.'

@Darkhax
Copy link
Collaborator

Darkhax commented Mar 2, 2022

Hello, thanks for reaching out about this. We are looking into including gametest examples with MultiLoader but it is a new system and we still have some stuff to learn. The CraftTweaker project has had some success with this, however their changes have not made it upstream yet. I will update this issue when we have more to add.

@LLytho
Copy link
Author

LLytho commented Mar 2, 2022

Hey,

with gametest you mean the mojang test suite from 1.18? But these are in the main sourceset or not?

@rlnt
Copy link

rlnt commented Mar 2, 2022

Forge patched that MinecraftForge/MinecraftForge#8225

@jaredlll08
Copy link
Owner

jaredlll08 commented Mar 2, 2022

with gametest you mean the mojang test suite from 1.18?

Yes, that is what Darkhax is talking about

But these are in the main sourceset or not?

It depends, the way I have them setup in CraftTweaker is that all the tests are in the gametest source set here
https://github.com/CraftTweaker/CraftTweaker/tree/1.18/Common/src/gametest

but the actual code to trigger those tests is in the Common main sourceset here:
https://github.com/CraftTweaker/CraftTweaker/blob/2b37f61bc0cc6dc163b41bdeaa4f5227c4a9053c/Common/src/main/java/com/blamejared/crafttweaker/gametest/CraftTweakerGameTests.java#L17

I forgot why I did it like this, I think I was having trouble getting the fabric entrypoint to see files in the gametest source set
https://github.com/CraftTweaker/CraftTweaker/blob/1.18/Fabric/src/main/resources/fabric.mod.json#L28

Unfortunately I don't have enough time on my hands to spend tinkering with it right now, but I was planning on relooking into it now that Forge has gametest support.

If you're talking about JUnit tests however, I did have those setup at some point using the test sourceset and they were running fine, the only issue was that you would need to bootstrap the game yourself, as well as bootstrapping mixin if you used it, which according to the mixin folk, wouldn't be too easy.
So I didn't really see it as a feasible approach for Multiloader based mods since you generally have a few mixins at-least in Fabric.

@LLytho
Copy link
Author

LLytho commented Mar 2, 2022

No JUnit, I mean just a second mod in the test sourceset which has access to the main sourceset of it's loader + Common and running them will result into having the mod Foo and FooTest as an example.

I did it for LootJS with 1.16 and before I knew about 1.18 GameTests. For a single module it was not that hard to setup. But now there is Common.main and Common.test to also consider and I had no success to implement them.

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

4 participants