ocadotechnology / test-arranger

Arranges test data as fully populated objects
Apache License 2.0
23 stars 2 forks source link

Feature Request/Proposal - configure bean initialization strategy #46

Closed jkatnik closed 1 year ago

jkatnik commented 1 year ago

Hello,

currently in TestArranger doesn't assign random values if the Kotlin constructor has default values. I was explained that this is a design choice within the Ocado organization.

As an external user, I'd like to be able to change that behavior via the properties file so that Test Arranger would fit my project needs.

data class Foo(
  val foo: String = "",
)

@Test
fun testSomeMethod() {
  val random = some<Foo>()
  assertThat(random.foo).isNotEmpty
}
mjureczko commented 1 year ago

Related issue: https://github.com/jkatnik/test-arranger/commit/469789ca192675e1f0b7c0b5ccfa164c6f3affd3

jkatnik commented 1 year ago

Hi @mjureczko

thank you for introducing that change so quickly.

Unfortunately, it doesn't work with Spring 2.7 because it is using Kotlin 1.6. by default.

using: testImplementation 'com.ocadotechnology.gembus:test-arranger:1.4.6 image

I haven't reported it earlier because I was hoping that I could convince my stakeholders to upgrade to spring boot 3.

mjureczko commented 1 year ago

Let me know if you can instantiate Foo using the arranger's java method, i.e.: Arranger.some(Foo::class.java).

Anyway, test-arranger does not depend on new Kotlin features, so I can change the Kotlin dependency to a lesser version on the 1.4.x line.

jkatnik commented 1 year ago

val foo = Arranger.some(Foo::class.java) works fine

jkatnik commented 1 year ago

@mjureczko regarding downgrading the Kotlin version in 1.4.x - it is a good idea, please release in your spare time, no hurry :)

mjureczko commented 1 year ago

@jkatnik version 1.4.6.1, with downgraded kotlin dependency, has been released

jkatnik commented 1 year ago

@mjureczko thanks!