Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Blockchain with Hyperledger

You're reading from  Hands-On Blockchain with Hyperledger

Product type Book
Published in Jun 2018
Publisher Packt
ISBN-13 9781788994521
Pages 460 pages
Edition 1st Edition
Languages
Concepts
Authors (6):
Nitin Gaur Nitin Gaur
Profile icon Nitin Gaur
Luc Desrosiers Luc Desrosiers
Profile icon Luc Desrosiers
Venkatraman Ramakrishna Venkatraman Ramakrishna
Profile icon Venkatraman Ramakrishna
Petr Novotny Petr Novotny
Profile icon Petr Novotny
Salman A. Baset Salman A. Baset
Profile icon Salman A. Baset
Anthony O'Dowd Anthony O'Dowd
Profile icon Anthony O'Dowd
View More author details
Toc

Table of Contents (20) Chapters close

Title Page
Copyright and Credits
Packt Upsell
Foreword
Contributors
Preface
1. Blockchain - Enterprise and Industry Perspective 2. Exploring Hyperledger Fabric 3. Setting the Stage with a Business Scenario 4. Designing a Data and Transaction Model with Golang 5. Exposing Network Assets and Transactions 6. Business Networks 7. A Business Network Example 8. Agility in a Blockchain Network 9. Life in a Blockchain Network 10. Governance, Necessary Evil of Regulated Industries 11. Hyperledger Fabric Security 12. The Future of Blockchain and the Challenges Ahead 1. Other Books You May Enjoy Index

Testing chaincode


Now we can write unit tests for our chaincode functions, we will use the in-built automated Go testing framework. For more information and documentation, visit Go's official website at: https://golang.org/pkg/testing/

The framework automatically seeks and executes functions with the following signature:

 func TestFname(*testing.T)

The function name Fname is an arbitrary name that must start with an uppercase letter.

Note that the test suite file containing unit tests must end with the suffix, _test.go; therefore, our test suite file will be named tradeWorkflow_test.go and placed in the same directory as our chaincode file. The first argument of the test function is of the type T, which provides functions for managing test states and supporting formatted test logs. The output of the test is written into the standard output, it can be inspected in the terminal.

SHIM mocking

The SHIM package provides a comprehensive mocking model that can be used to test chaincodes. In our unit...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}