ArchUnitの方がリフレクションAPIよりも利便性が高い理由

はじめに

私がArchUnitを理解するために公式ドキュメントを読んだ時のメモです。特にオチはないです。

ArchUnitの方がリフレクションAPIよりも利便性が高い理由

Why test your architecture? - ArchUnitの「Why use ArchUnit?」に、利便性が高い理由が載っています。
引用します。

ArchUnit provides simple predefined ways to test the typical standard cases, like package dependencies.
ArchUnitは、パッケージの依存関係など、typical standard cases(典型的な標準ケース)をテストするための簡単な定義済みの方法を提供します。

ここは「なるほどー」って感じですね。リフレクションAPIでテストを記述するより、typical standard casesについては、きっと簡潔で読みやすくなるのでしょう。

でも、続いて次の文章があります。

But it also is fully extensible, providing a convenient way to write custom rules where imported classes can be accessed similarly to using the Reflection API.
In fact, the imported structure provides a natural way to use the full power of the Reflection API for your tests.
ただし、完全に拡張可能で、インポートされたクラスにReflection APIを使用するのと同様にアクセスできるカスタムルールを記述する便利な方法を提供します。
実際、インポートされた構造は、テスト用にReflection APIのフルパワーを使用する自然な方法を提供します。

「typical standard casesをテストする方法提供しつつも、full power of the Reflection APIを使用する自然な方法も提供している…? どういうAPIの構成になっているんだろう??」と私は疑問に思いました。


この疑問はArchUnit User Guide - 5. Ideas and Concepts を読むと解消されました。

ArchUnit is divided into different layers, where the most important ones are the "Core" layer, the "Lang" layer and the "Library" layer. In short the Core layer deals with the basic infrastructure, i.e. how to import byte code into Java objects. The Lang layer contains the rule syntax to specify architecture rules in a succinct way. The Library layer contains more complex predefined rules, like a layered architecture with several layers.

441/5000
ArchUnitはさまざまなレイヤーに分割され、最も重要なレイヤーは「Core」レイヤー、「Lang」レイヤー、「Library」レイヤーです。 要するに、Coreレイヤーは基本的なインフラストラクチャ、つまりバイトコードJavaオブジェクトにインポートする方法を扱います。 Langレイヤーには、簡潔な方法でアーキテクチャルールを指定するためのルール構文が含まれています。 Libraryレイヤーには、複数のレイヤーを持つレイヤードアーキテクチャのような、より複雑な定義済みルールが含まれています。

ArchUnitはレイヤ分けして構成されていると。なるほどです。