-
Notifications
You must be signed in to change notification settings - Fork 46
Introduce Spring integration tests #2205
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
Conversation
cd12c2b
to
1448cc9
Compare
6dd562d
to
e295705
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utbot-instrumentation
lgtm
val classId: ClassId, | ||
val generics: List<FuzzedType> = emptyList(), | ||
) { | ||
open val usesCustomValueProvider get() = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inversion of dependencies between classes. FuzzedType should know nothing about how it is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like hasCustomCreationMechanism
could be a better name. The alternative is to make ObjectValueProvider
aware of AutowiredFuzzed
, but it seems more wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The better way I see is to use marker interface to implement, like:
interface CustomValueProvider {
fun getProvider(): ValueProvider
}
FuzzerType
itself shouldn't implement that interface, but AutowiredFuzzerType
should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, but I think this interface should be called CustomJavaValueProviderHolder
with val
property instead of the getter. In case of AutowiredFuzzedType
, javaValueProvider
can be injected into it via constructor by SpringFuzzedTypeFactory
so we avoid cyclic dependency between AutowiredFuzzedType
and AutowiredValueProvider
.
Finally, we can add DelegatingToCustomJavaValueProvider
to defaultValueProviders
.
interface CustomJavaValueProviderHolder {
val javaValueProvider: JavaValueProvider
}
object DelegatingToCustomJavaValueProvider {
fun accept(type: FuzzedType): Boolean = type is CustomJavaValueProviderHolder
fun generate(description: FuzzedDescription, type: FuzzedType): Sequence<Seed<FuzzedType, FuzzedValue>> =
(type as CustomJavaValueProviderHolder).javaValueProvider.generate(description, type)
}
There's nothing Java specific about the code above, but if we use generic ValueProviderHolder<T, R, D : Description<T>>
and DelegatingToCustomValueProvider<T, R, D : Description<T>>
then unsafe cast to ValueProviderHolder<T, R, D>
is needed instead of cast to CustomJavaValueProviderHolder
.
@@ -54,6 +54,7 @@ suspend fun runJavaFuzzing( | |||
constants: Collection<FuzzedConcreteValue>, | |||
names: List<String>, | |||
providers: List<ValueProvider<FuzzedType, FuzzedValue, FuzzedDescription>> = defaultValueProviders(idGenerator), | |||
thisInstanceFuzzedTypeWrapper: (FuzzedType) -> FuzzedType = { it }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look likes a workaround for a particular problem. Please, consider making it in more a general way. Also, the cache is used to keep types correctly, but know it is possible to make infinite recursive definition. Please, check that example like this method works correctly in test for the type resolving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can accept an instance of FuzzedTypeFactory
:
interface FuzzedTypeFactory {
fun createFuzzedType(type: Type, isThisInstance: Boolean)
}
It will have two implementations:
PureJvmFuzzedTypeFactory
traverses types recursively and incapsulates everythingcache
-relatedSpringFuzzedTypeFactory
is a decorator that makes this instance type to be autowired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good idea to use factory with decorators in this case 👍
utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt
Show resolved
Hide resolved
is ReplaceIfPossible -> false | ||
} | ||
SpringTestType.INTEGRATION_TESTS -> true | ||
} | ||
else -> UtSettings.useFuzzing | ||
} | ||
val rdGenerateResult = process.generate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it is time to write here smth like this:
val rdGenerateResult = process.generate(
conflictTriggers = model.conflictTriggers,
methods = methods,
mockStrategyApi = model.mockStrategy,
chosenClassesToMockAlways = model.chosenClassesToMockAlways,
timeout = model.timeout,
generationTimeout = model.timeout,
isSymbolicEngineEnabled = false,
isFuzzingEnabled = true,
fuzzingValue = project.service<Settings>().fuzzingValue,
searchDirectory = searchDirectory.pathString
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed with @EgorkaKulikov we can rebase it into the main, because it doesn't break general fuzzing, but we still need to refactor the Spring part in fuzzing module with @IlyaMuravjov to improve some concepts.
edaf990
to
81e364d
Compare
3ea574f
to
02607a1
Compare
Description
Introduce Spring integration tests that start
SpringApplication
and autowire tested class instance.How to test
Manual tests
Generate tests for
spring-boot-testing-main
after putting the following in theapplication.yml
.Self-check list