ExpectationFailedException */ public function assertSame($expected, $actual): void { if ($expected !== $actual) { throw new ExpectationFailedException('failure asserting that two variables'); } echo sprintf( 'success asserting that two variables %s and %s', var_export($expected, true) ?? 'null', var_export($actual, true) ?? 'null', ) . "\n"; } } class ExpectationFailedException extends \Exception {}
in the same method as the rest of the test. While in-line setup is the simplest test fixture to create, it leads to duplication when multiple tests require the same initial data. ◦ 要は、テストケース内で定義される形式 In-line setup
てのが図示されてる • > We are using a Fresh Fixture approach to build a Minimal Fixture for the use of this one test and we'd like to avoid Test Code Duplication. FYI: XUnitPatterns.comにはさっきのsetupも解説あり〼
in a setup method which is used to set up multiple test methods. This differs from delegate setup in that the overall setup of multiple tests is in a single setup method where the test fixture gets created rather than each test method having its own setup procedures and linking to an external test fixture. ◦ 単一のセットアップ処理で生成されて、それが複数のテストメソッドから 呼び出される ◦ 多くのアプリケーションフレームワークで標準装備されてるのは、この形 式のテストフィクスチャ管理になるはず Implicit setup
トフィクスチャにアクセスする、ってのが図 示されてる • > SImplicit Setup is a way to reuse the fixture setup code for all the Test Methods in a Testcase Class. FYI: XUnitPatterns.comにはさっきのsetupも解説あり〼
and build the test fixture such that only a single running of a single test will use it. We construct the fixture as part of running the test and tear down the fixture when the test has finished. ◦ テストケース実行するたびにビルドして、テストケース終わったら破棄 ◦ 基本的なフルスタックフレームワークはこれが前提だと思うで • > When each test creates a Fresh Fixture, it prevents Erratic Tests and is more likely to result in Tests as Documentation. ◦ Fresh Fixtureを採用すると、不規則なテストがなくなるし”Tests as Documentation(ドキュメントとしてのテスト)”となってよいわよ ◦ あれ?最強そうじゃん?? これらのsetupは”Fresh Fixture”という戦略の上にある
Testing Overview の序文 ◦ > If you have a robust testing practice, you needn’t fear change—you can embrace it as an essential quality of developing software. The more and faster you want to change your systems, the more you need a fast way to test them. ▪ システムをスピード感持って変更するためには、より高速なテスト実 行環境が必要だよ • Fresh Fixtureは都度読み込むから実行コスト/速度がかかりそうね...?? そもそも、テストスイートに重要な観点って何?
an automated test, we require a text fixture that is well understood and completely deterministic. Setting up a Fresh Fixture can be time consuming, especially when dealing with complex system state stored in a test database. ▪ “Fresh Fixture”だと都度テストフィクスチャをsetupするから時間かか るのよね ▪ あっ基本的にデータ投入して用意しとくから使ってや!なあ兄ちゃん • これってテストケースの実行サイクルとは別に、”すでに用意され ているテストフィクスチャ”として扱う必要があるのよね 高速化のためのテストフィクスチャ戦略
Fixture is a way to reuse the same fixture design in several tests without necessarily sharing the same fixture instance. ▪ 使い回せるような、Standardなテストフィクスチャを設計しような! • cf. Minimal Fixture at XUnitPatterns.com ◦ > A key part of understanding a test is understanding the test fixture and how it influences the expected outcome of the test. Tests are much easier to understand if the fixture is small and simple. ▪ 余計な要素を削ることでテストフィクスチャの内容を把握するぞ! • これらの戦略も決定論的にテストフィクスチャを整理するための戦略 高速化のためのテストフィクスチャ戦略
function setDefaultTemplate(): void の中で定義されているデータをセットアップす るだけ 具体的にはこんな感じに使えるよん public function test_getUserById(): void { // given $userFactory = UserFactory::make();