단위 테스트(Unit Testing)
단위 테스트를 사용하면 컨트랙트 메서드를 개별적으로 테스트할 수 있습니다. 이는 스토리지가 올바르게 업데이트되었는지 확인하고, 메서드가 예상 값을 반환하는지 확인하는 데 적합합니다. 이는 컨트랙트의 언어로 작성되고 로컬에서 실행됩니다.
예제 중 하나를 템플릿으로 사용한 경우, 컨트랙트 폴더로 이동하여 yarn test
를 사용하세요. 그렇지 않은 경우 템플릿 중 하나에서 필요한 노드 파일(예: package.json
)을 복사하는 것이 좋습니다.
팁
각 프로젝트의 루트 폴더에서
yarn test
를 실행하여 단위 테스트와 통합 테스트를 모두 실행할 수 있습니다 ::::::
스니펫 I: Counter 테스트
The tests in the Counter Example rely on basic functions to check that the increment
, decrement
, and reset
methods work properly.
- 🦀 Rust
contract-rs/src/lib.rs
loading...
Snippet II: Modifying the Context
While doing unit testing you can modify the Environment variables through the VMContextBuilder
. 이를 통해, 예를 들어 보증금 및 가스가 첨부된 다른 사용자의 호출을 시뮬레이션할 수 있습니다. Here we present a snippet on how we test the donate
method from our Donation Example by manipulating the predecessor
and attached_deposit
.
- 🦀 Rust
contract-rs/src/lib.rs
loading...