About Cosense
Help
Log in
mrsekut-p
R
e
p
o
s
i
t
o
r
y
の
t
e
s
t
f
r
o
m
R
e
p
o
s
i
t
o
r
y
P
r
i
s
m
a
の
t
e
s
t
/
m
r
s
e
k
u
t
-
b
o
o
k
-
4
8
3
9
9
8
1
7
2
8
/
3
4
4
(
第
1
0
章
デ
ー
タ
ベ
ー
ス
に
対
す
る
テ
ス
ト
)
>
#
W
I
P
/
m
r
s
e
k
u
t
-
b
o
o
k
-
4
8
3
9
9
8
1
7
2
8
/
3
5
9
t
r
a
n
s
a
c
t
i
o
n
を
U
n
i
t
O
f
W
o
r
k
に
変
換
す
る
こ
れ
は
実
装
部
分
の
話
/
m
r
s
e
k
u
t
-
b
o
o
k
-
4
8
3
9
9
8
1
7
2
8
/
3
6
2
1
つ
の
t
e
s
t
c
a
s
e
内
の
A
A
A
パ
タ
ー
ン
の
異
な
る
フ
ェ
ー
ズ
で
、
同
じ
t
r
a
n
s
c
a
t
i
o
n
や
U
n
i
t
O
f
W
o
r
k
を
使
い
回
さ
な
い
ど
う
い
う
こ
と
?
な
ぜ
?
T
e
s
t
c
o
n
t
a
i
n
e
r
s
殆
ど
、
デ
ー
タ
整
形
し
か
無
い
場
合
は
テ
ス
ト
の
必
要
性
を
そ
も
そ
も
あ
ま
り
感
じ
な
い
mrsekut
テ
ス
ト
の
要
件
が
見
え
て
い
な
い
何
を
テ
ス
ト
す
れ
ば
い
い
の
か
が
わ
か
ら
な
い
D
B
の
内
容
が
お
か
し
い
こ
と
の
テ
ス
ト
と
か
?
R
e
p
o
s
i
t
o
r
y
が
c
a
c
h
e
を
管
理
し
て
い
る
と
き
は
、
c
a
c
h
e
の
テ
ス
ト
と
か
か
c
a
c
h
e
に
デ
ー
タ
が
有
れ
ば
そ
れ
を
返
し
て
、
な
け
れ
ば
ど
こ
か
か
ら
取
っ
て
く
る
、
と
か
g
e
t
U
s
e
r
B
y
I
d
(
n
u
m
b
e
r
)
と
か
で
、
ち
ゃ
ん
と
u
s
e
r
が
返
っ
て
く
る
か
と
か
か
D
B
も
d
u
m
m
y
で
あ
っ
て
ほ
し
い
S
Q
L
は
仕
様
の
列
挙
が
型
で
で
き
な
い
の
で
、
仕
様
の
列
挙
の
た
め
に
も
、
R
e
p
o
s
i
t
o
r
y
の
t
e
s
t
が
ほ
し
い
mrsekut
S
Q
L
の
正
当
性
の
t
e
s
t
こ
の
場
合
に
、
実
際
の
D
B
を
見
て
テ
ス
ト
す
る
の
か
、
こ
の
場
合
、
c
i
な
ど
も
鑑
み
て
、
そ
の
環
境
を
簡
易
に
作
れ
る
よ
う
に
し
て
お
く
必
要
が
あ
る
モ
ッ
ク
的
な
も
の
を
用
意
す
れ
ば
そ
れ
で
済
む
の
か
モ
ッ
ク
を
用
意
す
る
場
合
ど
の
よ
う
に
用
意
す
る
の
か
S
Q
L
の
t
e
s
t
c
o
d
e
r
e
p
o
s
i
t
o
r
y
層
を
m
o
c
k
す
る
こ
れ
は
r
e
p
o
s
i
t
o
r
y
に
依
存
す
る
も
の
を
テ
ス
ト
す
る
時
の
話
な
の
で
、
こ
の
ペ
ー
ジ
に
は
関
係
な
い
t
e
s
t
時
に
D
B
M
S
を
動
か
す
h
t
t
p
s
:
/
/
w
w
w
.
m
i
z
d
r
a
.
n
e
t
/
e
n
t
r
y
/
2
0
2
2
/
1
1
/
2
4
/
1
5
3
4
5
9
w
i
t
h
P
r
i
s
m
a
m
o
c
k
を
使
わ
な
い
テ
ス
ト
>
@
t
_
w
a
d
a
:
デ
ー
タ
ア
ク
セ
ス
レ
イ
ヤ
の
テ
ス
ト
を
書
く
際
に
D
B
を
モ
ッ
ク
す
る
の
は
自
作
自
演
の
テ
ス
ト
に
な
り
が
ち
な
の
で
個
人
的
に
は
お
す
す
め
し
ま
せ
ん
/
“
P
r
i
s
m
a
で
本
物
の
D
B
M
S
を
使
っ
て
自
動
テ
ス
ト
を
書
く
-
m
i
z
d
r
a
'
s
b
l
o
g
”
h
t
t
p
s
:
/
/
t
.
c
o
/
3
Y
I
c
K
3
p
t
U
9
d
o
c
k
e
r
t
e
s
t
h
t
t
p
s
:
/
/
q
u
r
a
m
y
.
m
e
d
i
u
m
.
c
o
m
/
i
n
t
e
g
r
a
t
e
d
-
t
e
s
t
i
n
g
-
w
i
t
h
-
p
r
i
s
m
a
-
4
b
c
7
3
4
0
4
d
0
2
7
P
r
i
s
m
a
実
際
の
D
B
と
通
信
し
て
テ
ス
ト
h
t
t
p
s
:
/
/
z
e
n
n
.
d
e
v
/
t
a
k
e
p
e
p
e
/
a
r
t
i
c
l
e
s
/
n
e
x
t
j
s
-
t
e
s
t
i
n
g
-
s
t
r
a
t
e
g
y
-
2
0
2
2
A
P
I
の
t
e
s
t
Related
Sort by
Related
Modified
Created
Last visited
Most linked
Page rank
Title
Links
APIのtest
>#wipどういう目的に備えるためのtestかDBをupgradeした際に、既存の全APIが壊れていないか確認したいDBとやり取りするライブラリの整合性SQLの書き方の変更
Repository
Prisma
Testcontainers
[website https://testcontainers.com/][Repositoryのtest][https://zenn.dev/shiguredo/articles/sqlc-gen-typescript これ]のコード片読んで雰囲気が掴めた`test("account", async () => {``// コンテナ作成`
dockertest
from [Repositoryのtest]test時にdockerを起動してテストするhttps://github.com/ory/dockertesthttps://zenn.dev/shiguredo/articles/go-test-dockertesthttps://gihyo.jp/article/2023/12/tukinami-go-09
SQLのtest code
>#WIP[/kawasima/Queryのユニットテスト]今のところ良い感じの解法はないっぽい[DBUnit]SQLが正しいかどうかを検証するテストってどう書くの #??
Unit Of Work
object modelに変更があるたびにDBに反映するのではなく、いくつかの変更をまとめて、DBに反映する[transaction]よりも大きい単位でcommitする感じのやつ[transaction]もUnit Of Workの一つとも言えるUnit Of Workの中の最小が[transaction]みたいな感じか
AAAパターン
[Give-When-Thenパターン]もほぼ同じ1つの[test case]の中で、以下をこの順番に1度ずつ行うArrangetestの[事前条件]を満たすように、[SUT]や[DOC]を用意する通常は、Arrangeに書くものが最も多くなる
WIP
Work In Progress[WIPを明示するためにノートを罫線で分割する]
backendのtest
関連[APIのtest][Repositoryのtest]
『単体テストの考え方/使い方』
GitHub ActionsのService Containers
https://docs.github.com/ja/actions/use-cases-and-examples/using-containerized-services/about-service-containersCI上での[Repositoryのtest]とかに使えそう[GPT-4.icon]テストにおけるService Containerの活用例DBへの接続確認・データベース統合テスト
Repository
JSConfJP2019 day2
『エリック・エヴァンスのドメイン駆動設計』
Aggregate
Transaction Script
CA:Gateways
[Repository]
RepositoryとDAOの違い
[Repository]の方が抽象度が高いRepositoryはAggregateを扱うRepository == DAOとなるケースも有り得るDAOがデータ中心指向であるのに対して、リポジトリはオブジェクト指向アプローチである点で異なる [ref https://codezine.jp/article/detail/11048#:~:text=%E9%9B%86%E4%B8%AD%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82-,%E3%83%AA%E3%83%9D%E3%82%B8%E3%83
Persistence Ignorance
[永続性非依存]今や当たり前になっているが[mrsekut.icon]Entityは永続性に依存してはいけないよ、という原則[Repository]とかhttps://www.infoq.com/jp/news/2013/09/orm-persistence-ignorance/
Service Class
>#WIPService Classってなんやねん独自の状態を持たない結果として、特定のドメインのutil関数群みたいな感じになる?手続の集合
DDDとCAの用語
Prismaのtest
Vitest: globalSetup
from [vitest.config.ts]https://vitest.dev/config/#globalsetupテストの実行前に一度だけ呼ばれるglobalな準備処理を行うファイルを指定する用途の例テスト用のデータベースの起動・初期化
@quramy/prisma-fabbrica
from [Prisma][Prisma SchemaのGenerator][github https://github.com/Quramy/prisma-fabbrica][https://quramy.medium.com/integrated-testing-with-prisma-4bc73404d027 Integrated testing with Prisma. Prisma を利用する上で、テストの書きづらさがあったため、OSS を 2… | by Yosuke Kurami | Medium]
AAAパターン
意図と可読性のあるtest codeを書く
[Test Code]全般を書く時に心がける点について個別的な分析手法とか、具体的なフレームワークには言及せずに参考[https://qiita.com/yonetty/items/7787a539d77396a3807e リーダブルテストコード - Qiita]テストコードに対する知識が少ないと、一番最初の悪い例が、そもそも「これ悪いんだ」という感想になる[mrsekut.icon]
『Clean Craftsmanship』
Testcontainers
sqlc-gen-typescript
from [sqlc][sqlc]のts版[github https://github.com/sqlc-dev/sqlc-gen-typescript][sqlc-gen-ts-template][https://github.com/voluntas/sqlc-gen-ts-template github]
SQLのtest code
SQL
[/ Structured Query Language]Playground[DB Fiddle]学習サービスhttps://gothedistance.hatenadiary.jp/entry/2019/12/25/110000
『理論から学ぶデータベース実践入門』
2 Way SQL
#??どういういもの?なぜ必要になる?[uroboroSQL]https://github.com/future-architect/uroborosql/tree/master
Prisma
ORM
[/ Object-relational mapping]オブジェクト関係マッピング>#WIP[インピーダンス・ミスマッチ]の解消上手く言語化できないが、「SQLの代替手段としてのORM」という戦略自体がズレている気がする
NextAuthのAdapters
@prisma/instrumentation
[OpenTelemetry] compliant instrumentation for [Prisma] Client.https://www.npmjs.com/package/@prisma/instrumentationhttps://azukiazusa.dev/blog/prisma-opentelemetry-trace/https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/opentelemetry-tracing
GraphQL Playground
[Prisma]のチームが作ったブラウザ上で見れるやつと、Desktopアプリとある[github https://github.com/prisma-labs/graphql-playground][website https://www.electronjs.org/apps/graphql-playground][GraphiQL]と違って
Blitz.js
まだα版[React]向けの[Ruby on Rails]みたいなやつ[Next.js]上で使えるfolkするらしい [ref https://qiita.com/rana_kualu/items/69ef668e240ae9ccec87]TypeScript first
Prisma Pulse
https://www.prisma.io/data-platform/pulsehttps://www.prisma.io/blog/introducing-pulse-jtu4UPC8ujy4[Prisma]マネージド[CDC]サービス[Logical Replication]ってなに?
Hasura
[/ Harsura GraphQL Engine]部類としては[GraphQL Server]ただ、他の一般的な[GraphQL Server]よりも能力が強い具体的には、[GraphQLのResolver]や[GraphQLのDataSource]を書かなくて良いそういう点を指して解説記事では「自動でGraphQL serverを立ててくれる」とか言っている
TypeScriptのORM
[/miyamonz/js ,tsのORM][TypeORM][Prisma][Kysely][Drizzle ORM]
Prisma Engines
from [Prisma]https://www.prisma.io/docs/concepts/components/prisma-engines[github https://github.com/prisma/prisma-engines][Rust実装]
Redwoodjs
typegraphql-prisma
[TypeGraphQL]と[Prisma]と連携するlibraryPrisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schemaPrismaのschemaから、TypeGraphQLのclassのやつを作る?[website https://prisma.typegraphql.com/][github https://github.com/MichalLytek/typegraphql-prisma]
Wasp
A simple language for developing full-stack web apps with less code.Webアプリケーションを作るための[DSL]ノリ的にはElmが近いが、Elmと違ってbackendやdeploy部分も補う[github https://github.com/wasp-lang/wasp][Haskell実装]
APIのtest
Hurl
runn
[github https://github.com/k1LoW/runn]開発者は[@k1LoW]https://zenn.dev/katzumi/articles/api-scenario-testing-with-runnhttps://tech.pepabo.com/2022/06/07/scenario-testing-in-go/ymlでテストケースを書いて、[APIのtest]をするつーる
New Links
test時にDBMSを動かす
Created
3 years ago
by
mrsekut-bot
Updated
3 months ago
by
mrsekut-bot
Views: 64
Page rank: 35
Copy link
Copy readable link
Start presentation
Hide dots
Repositoryのtest
from
Repository
Prismaのtest
/mrsekut-book-4839981728/344 (第10章 データベースに対するテスト)
#WIP
/mrsekut-book-4839981728/359
transactionを
Unit Of Work
に変換する
これは実装部分の話
/mrsekut-book-4839981728/362
1つのtest case内の
AAAパターン
の異なるフェーズで、同じtranscationや
Unit Of Work
を使い回さない
どういうこと?
なぜ?
Testcontainers
殆ど、データ整形しか無い場合はテストの必要性をそもそもあまり感じない
mrsekut.icon
テストの要件が見えていない
何をテストすればいいのかがわからない
DBの内容がおかしいことのテストとか?
Repositoryがcacheを管理しているときは、cacheのテストとかか
cacheにデータが有ればそれを返して、なければどこかから取ってくる、とか
getUserById(number)
とかで、ちゃんとuserが返ってくるかとかか
DBもdummyであってほしい
SQLは仕様の列挙が型でできないので、仕様の列挙のためにも、Repositoryのtestがほしい
mrsekut.icon
SQLの正当性のtest
この場合に、実際のDBを見てテストするのか、
この場合、ciなども鑑みて、その環境を簡易に作れるようにしておく必要がある
モック的なものを用意すればそれで済むのか
モックを用意する場合どのように用意するのか
SQLのtest code
repository層をmockする
これはrepositoryに依存するものをテストする時の話なので、このページには関係ない
test時にDBMSを動かす
https://www.mizdra.net/entry/2022/11/24/153459
with
Prisma
mockを使わないテスト
@t_wada
: データアクセスレイヤのテストを書く際にDBをモックするのは自作自演のテストになりがちなので個人的にはおすすめしません / “Prisma で本物のDBMSを使って自動テストを書く - mizdra's blog”
https://t.co/3YIcK3ptU9
dockertest
https://quramy.medium.com/integrated-testing-with-prisma-4bc73404d027
Prisma
実際のDBと通信してテスト
https://zenn.dev/takepepe/articles/nextjs-testing-strategy-2022
APIのtest