I want to test some contracts^^ And now Im wondering because like I understand .deployed() should take the contracts from the migration in truffle and dont deploy new ones?

My test.js:

const one = artifacts.require("One.sol");
 const two= artifacts.require("Two.sol");

 contract('One and Two', async (accounts) => {

    let instance;

    let deployAccount = accounts[1];
    before(async () => {
        ione= await one.deployed();
        itwo= await two.deployed();
    it("Two: should return the owner", async ()=> {
        const value = await itwo.getOwner.call();
        assert.equal(value, deployAccount);

In my ganache browser I can see that always I run truffle test there will be 3 contracts deployed... (the default contract Migration.sol is the 3rd) But I only see the contracts that get deployed with "truffle migration"

So my question is:

Is it possible to dont deploy by running "truffle test" without deploying contracts that allready in ganache? Or is it possible to update ganache to see the last contract in the writer "contracts" that have been deployed?

1 Answer 1


You are correct. When using .deployed() you basically retrieve the contract that has been deployed by your Migrations (you can see the deployed contract address in your generated ABI under /build/YourContract.json).

However when you test with Ganache then Truffle creates what they call a "Cleam Room Environment". This basically means that Truffle will re-deploy all of your migrations at the beginning of every test file to ensure you have a fresh set of contracts to test against.

If you want to use your previous contracts and not re-deploy them automatically, you could have your Migration use the overwrite:false option:

// Don't deploy this contract if it has already been deployed
deployer.deploy(A, {overwrite: false});
  • Thanks for the fast answere I added: const one = artifacts.require("one"); module.exports = function(deployer, network, accounts) { deployer.deploy(one, { override:false, from: accounts[1] }); } to my migration file but it still the same behavior. The contracts get everytime deployed when I run "truffle test"
    – MaTok
    Commented Dec 19, 2020 at 14:53
  • @MToken I seem to be having issues reproducing the override:false too... What you could do instead of using deployed() is to deploy your contracts first and then set the address like this ione = await one.at("0x....")
    – valdi.k
    Commented Dec 21, 2020 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.