wpilibsuite / vendor-template

10 stars 14 forks source link

Configure template for Java unit tests #14

Open mjansen4857 opened 1 year ago

mjansen4857 commented 1 year ago

The template already includes configuration for running unit tests on native code, but does not include configuration for any Java tests. I have added my own configuration as is documented here for robot projects:

dependencies {
    ...

    testImplementation 'junit:junit:4.12'
}

...

test {
    useJUnit()
}

This works fine unless a test requires use of the HAL i.e. HAL.initialize(500, 0). This will throw an exception:

java.io.IOException: wpiHaljni could not be loaded from path or an embedded resource.
    attempted to load for platform /windows/x86-64/

I have tried this on a fresh copy of the template on a couple different computers that are able to run these tests just fine in a robot project, so I believe there is some extra configuration that the GradleRIO plugin would normally take care of and not an issue with my system.

ThadHouse commented 1 year ago

There is extra configuration gradlerio does to enable testing. It’s a bit more complex to add here, the solution is to create an executable, and then use some gradle magic to make the unit tests depend on that executable, and use that executable to find the native libraries.

mjansen4857 commented 1 year ago

That sounds far beyond my gradle ability. Does it make sense to add this change to the template?