(Funny talk) What is the difference between `test` and `test fixture`

It is just funny talk, hope it does not disturbing.

I saw my colleague used a feature of Gradle, called java-test-fixtures. Then I got wondered, “What is a test fixture”. After checking the code of JavaTestFixturesPlugin. I found that test fixture is nothing, but anthoer name for testImplementation (May I am wrong, since my knowledge about it is poor). It just added another java sourceSet, which performed same as what testImplementation did.

Acctually, I am kind of got the idea, that it might want to create a specific way to publish a test library. But still, it just did get away from my mind, “Why there is a java-test-fixtures feature, even that we already can import test depedencies from testImplementation”.

I checked gradle document, the part about test fixture: Testing in Java & JVM projects. Also I read the article from baeldung https://www.baeldung.com/gradle-6-features. It seems, they are talking the same thing like what I found.

Same, I did can get the idea of source sets of java, scala, antlr, protobuf etc. And even not doubt it for any second. Maybe it just becuase there is already have a way to publish test sources. Or there is a thought in my mind, people should not mix up any module’s responsibility. Which means, if you are a module for bussiness, then you should not try to do utility’s work. Therefore, I did seprating my code with different responsibility, in a strict way.

So, I got here, want to disscus with you guys about it. Hope that anyone could inspire me and tell my that “your thought is dangerous, haha”

You are mixing things a bit.
testFixtures is not another name for testImplementation.
testImplementation is a configuration where you can define dependencies for implementing tests.
testFixtures is an additional source set where you can put classes in, that other projects should be able to depend on, for example with test fixtures in them.
In testFixtures you typically do not put tests, but helpers or fixtures that tests of other projects should be able to use.
You can of course also configure test to be published so that other project can depend on, but that is a mix of responsibilities. test is for actual tests.
testFixtures is for such helpers or fixtures also other projects should be able to use and is out-of-the box configured to be published and with helper methods to conveniently depend on this feature variant.
You can of course also have a separate project that contains those test fixtures or helpers, but often this would be overkill and architecturally better in a feature of the project in question.

My Mr. Vampire. Nice to meet you.

I started to get this idea a little. testFixutures is a less strict way to achieve it, separating utility part from logic test codes. A single project to manage all test facilities, sometimes, is exhausting. Not all of us need to concern that. In that case, this could, be a convenient solution.

1 Like