Good morning, does anyone have any suggestions on ...
# community-support
d
Good morning, does anyone have any suggestions on how I can test
useJUnitPlatform()
without relying on the internal
JUnitPlatformTestFramework
class? Currently I'm using this to check:
Copy code
project.tasks.withType(Test).forEach {
    assert it.testLogging.exceptionFormat == TestExceptionFormat.FULL
    assert it.testFramework instanceof JUnitPlatformTestFramework
}
I'd also like to test against the
ResolutionStrategy.cacheChangingModulesFor(int value, TimeUnit units)
method to confirm behavior is working as expected. For this one I've been reliant on the
DefaultCachePolicy
internal class (since I'm doing a cast to a
DefaultResolutionStrategy
(also internal)) and then accessing the
cachePolicy
field.
a
I guess technically speaking you can check the options - those aren't internal 🤔
Copy code
tasks.test {
    useJUnitPlatform()
    assert getOptions() instanceof JUnitPlatformOptions
}
👀 1
☝️ 1
But your code is ringing alarm bells for me! It's breaking some Gradle idioms. Can you explain more about what you want to achieve? Why do you want to assert that JUnit Platform is used?
d
This is a unit test against one of our Gradle plugins - we want to ensure that the standard being provided is indeed the JUnit Platform.
And then here's how I'm currently testing `ResolutionStrategy.cacheChangingModulesFor(0, 'seconds')`:
Copy code
project.configurations.forEach {
    assert ((DefaultCachePolicy)((DefaultResolutionStrategy) it.resolutionStrategy).cachePolicy).keepChangingModulesFor == 0
}
a
Ahh right! You're using TestKit (or something else?) to run an integration test.
d
I think it's TestKit - not sure the terminology - but I use
ProjectBuilder.builder().build()
to create a test project to see if defaults provided by the plugin are being applied.
a
ah okay, cool. What you're doing makes a lot more sense, thanks!
ProjectBuilder isn't TestKit, but it's the right choice for what you're doing
👍 1
And you're trying to verify that your plugin calls
cacheChangingModulesFor()
?
d
I guess a call might work, but really wanting to check that changing modules are kept for 0 seconds. Which I guess could be tested using the call instead
So I've got this, but it seems to always pass (100 is just a random number I'm using to verify it always passes):
Copy code
project.configurations.forEach {
    100 * it.resolutionStrategy.cacheChangingModulesFor(_, _)
}
I guess I'm not mocking any of the
ResolutionStrategy
objects, so this wouldn't work.