For testing with truffle you need to get the truffle suite work. That means, running a test blockchain. So first run ganache or ganache-cli. This is the place you will deploy your contract with truffle test.
Since ganache and ganache-cli answer to differnt ports, you may make two entries for both in your truffle.js (Windows I think truffle-js). This file should exist and it is normaly created during install of truffle:
ganache defaults to port 7545
ganache-cli defaults to port 8545
So here are some modificaton for truffle js in your truffle project root directory:
open the file and goto module.export object. Then you may add
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// for more about customizing your Truffle configuration!
networks: {
ganacheCLI: {
host: '127.0.0.1',
port: 8545,
network_id: '*', // Match any network id
},
ganache: {
host: '127.0.0.1',
port: 7545,
network_id: '*', // Match any network id
},
},
To test your truffle.js file. Start ganache or ganache-cli
truffle console --network ganache
or
truffle console --network ganacheCLI
If truffle console connects, your truffle.js config is fine.
So then you can goto to the test directory and add a file, for example MyFirstContract.test.js
For testing type a console.log(‘MyFirstContract is alive’);
Then truffle test -network ganache and it should work.
After that start with programming the testcode
BTW. one single tip. Avoid naming files test*, contracts or methods test. This is a good practice and avoids problems, because often test is a predefined keyword.
Hope this helps