-
Notifications
You must be signed in to change notification settings - Fork 494
Test Driven Development
Iuri Matias edited this page Aug 9, 2016
·
5 revisions
You can run specs with embark spec
, it will run any files ending *_spec.js under spec/
.
Embark includes a testing lib to fastly run & test your contracts in a EVM. To require Embark's Testing Module do:
EmbarkSpec = require('embark-framework').Tests
Afterwards you can initialize a contract and pass arguments to its contractor:
SimpleStorage = EmbarkSpec.request("SimpleStorage", [150]);
Embark will look for the contract at app/contracts/*
, compile it and run it in a VM. You can then interact with the contract normally. e.g SimpleStorage.set(100)
A caveat at the moment is that the return values are represented as strings. So SimpleStorage.get()
will return "100"
e.g
# spec/contracts/simple_storage_spec.js
EmbarkSpec = require('embark-framework').Tests;
describe("SimpleStorage", function() {
beforeAll(function() {
// equivalent to initializing SimpleStorage with param 150
SimpleStorage = EmbarkSpec.request("SimpleStorage", [150]);
});
it("should set constructor value", function() {
expect(SimpleStorage.storedData()).toEqual('150');
});
it("set storage value", function() {
SimpleStorage.set(100);
expect(SimpleStorage.get()).toEqual('100');
});
})
Embark uses Jasmine by default, but you can use any testing framework you want.