Skip to content
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

議事録-2023-01-14-Sat #113

Open
kinari321 opened this issue Jan 13, 2023 · 3 comments
Open

議事録-2023-01-14-Sat #113

kinari321 opened this issue Jan 13, 2023 · 3 comments
Assignees

Comments

@kinari321
Copy link
Contributor

kinari321 commented Jan 13, 2023

前回の議事録

前回

  • 特になし

前回から今回まで

  • 特になし

決めたいこと・相談事項

今回やったことまとめ

今回 Merge した Pull Request

次(予定)

  • 投稿(Post)モデルを作る
@sunakan
Copy link
Contributor

sunakan commented Jan 13, 2023

https://github.com/sunabak0/realworld-kotlin-springboot-jdbc/blob/5c394e8d9e8ca7af9c863f623fba4108c31ad6e5/src/test/kotlin/com/example/realworldkotlinspringbootjdbc/api_integration/DefaultTest.kt#L51-L70

            val actualStatus = response.status
            val actualResponseBody = response.contentAsString

            /**
             * then:
             * - ステータスコードが一致する
             * - レスポンスボディが一致する
             */
            val expectedStatus = 200
            val expectedResponseBody = """
                {
                  "tags": ["rust", "scala", "kotlin", "ocaml", "elixir"]
                }
            """.trimIndent()
            // ステータスコードが一致するかどうかのテスト
            Assertions.assertThat(actualStatus).isEqualTo(expectedStatus)

            // JSONとして合ってるかどうか比較テスト
            JSONAssert.assertEquals(
                expectedResponseBody,
                actualResponseBody,
                // 厳しさ具合(拡張禁止、順番は守らなくていい)
                CustomComparator(JSONCompareMode.NON_EXTENSIBLE)
            )

Kotlin(Spring Boot)の API テスト(MockMVC)で CustomComparator を用いて独自の比較方法を作成 > JSONCompareMode について

@sunakan
Copy link
Contributor

sunakan commented Jan 13, 2023

JSONAssert.assertEqualsで文字列一致ではなく、JSON一致で比較

{
  "name": "john",
  "arr": [1,2,3,4]
}

{"arr": [1,2,3,4], "name": "john"}

は同じ

@kinari321
Copy link
Contributor Author

kinari321 commented Jan 13, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants