Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Truffle Quick Start Guide

You're reading from   Truffle Quick Start Guide Learn the fundamentals of Ethereum development

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781789132540
Length 170 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Nikhil Bhaskar Nikhil Bhaskar
Author Profile Icon Nikhil Bhaskar
Nikhil Bhaskar
Arrow right icon
View More author details
Toc

Writing unit tests with JavaScript

Inside the contracts folder, create a .js file that will house our tests; call it test-task-master.js.

Again, stick to the same practice of prepending our contract name with the word test so that it's clear that it's a test file. I prefer JavaScript file names to be snake case, but if you prefer camelCase file names, that is fine too.

Inside the test-task-master.js file, let's import our contract so we can make use of it in our tests:

const TaskMaster = artifacts.require("../contracts/TaskMaster.sol");

artifacts is automatically injected by Truffle inside our test environment, and it allows us to instantiate our contract easily for the purpose of testing.

Next, let's define a function where we will place all of the unit tests of our contract. Underneath the artifacts.require statement, add the following block of...

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 $19.99/month. Cancel anytime
Banner background image