Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

jqwikをSpringBootのAPIテストでも使いたい #283

@sunakan

Description

@sunakan

概要

jqwikをもっと使いこなせば、少し幸せになりそう

背景

APIテストのレビューで自作jqwik的なやつがあったのでjqwikを使ったテストを提案しようとしたが、動かなかった

エラー

lateinit property mockMvc has not been initialized
kotlin.UninitializedPropertyAccessException: lateinit property mockMvc has not been initialized
...

mockMvcのAutowiredによるintializeで失敗してそう

思いつく解決方法

  • mockMvcをAutowiredしないで使う
    • どうやってやるかは今後の調査しだい(できないかもしれない、 @SpringBootTest を利用しているので難しいかもしれない)
  • jqwikを @ForAll とかなしに直接callする
    • どうやってやるかは今後の調査(想定されていないかもしれない)
  • jqwikのspring拡張を入れる&コントリビュートして最新対応
    • 理想だけど、一番つらそう

レビューでは以下を提案しようとしたのですが、ダメでした

        @Example
        fun `準正常系-slug が無効な値の場合、NotFoundError が返される`(
            @ForAll @AlphaChars @NumericChars @StringLength(min = 33) tooLongSlug: String
        ) {
            /**
             * given:
             * - 32文字より大きい場合
             */
            val pathParameter = tooLongSlug

としようとすると、Beanのinitialize周りで怒られました

jqwikの spring 拡張がありそうでしたが、メンテはそんなにする気は無さそうでした
力がついたらcontributeしても良いかもしれませんが、今は断念

https://github.com/jlink/jqwik-spring

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions