# How to setup testing environment for smart contract in solidity

I am following https://truffleframework.com/docs/getting_started/solidity-tests to set up a test in solidity for smart contract. Here is my test.sol

pragma solidity ^0.4.17;

import "truffle/Assert.sol";
import "../contracts/Auction.sol";

const Auction_sol = artifacts.require("./Auction.sol");

contract TestAuction {

}


But I am constantly have the error below about missing artifacts:

Error: Could not find artifacts for ./test.sol from any sources
at Resolver.require (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\.-resolver\index.js:37:1)
at TestResolver.require (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\.-core\lib\testing\testresolver.js:17:1)
at C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\.-core\lib\test.js:109:1
at Array.map (<anonymous>)
at C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\.-core\lib\test.js:107:1


What I am missing here? It seems to be simple task but somehow the online post did not work for me.

Here is the 2_deploy_contracts.js

var Auction = artifacts.require("Auction");
const Auction_sol = artifacts.require('Auction.sol');  //this line seems no use

module.exports = function(deployer) {
deployer.deploy(Auction);
},


Here is the portion of smart contract:

pragma solidity ^0.4.17;
contract Auction {

// Data
//Structure to hold details of the item
struct Item {
uint itemId; // id of the item
uint[] itemTokens;  //tokens bid in favor of the item

}

//Structure to hold the details of a persons
struct Person {
uint remainingTokens; // tokens remaining with bidder
uint personId; // it serves as tokenId as well
}

Person [4] bidders;//Array containing 4 person objects

Item [3] public items;//Array containing 3 item objects
address public beneficiary;//owner of the smart contract

uint bidderCount=0;//counter

//functions

function Auction() public payable{    //constructor
......................


If you're new to Truffle, I encourage you to start with Ethereum pet shop -- your first dapp.

pragma solidity ^0.4.17;

import "truffle/Assert.sol";
import "../contracts/Auction.sol";

contract TestAuction {

}


Edit:

Error is because name of your test contract file and actual contract name are different. Your contract filename and contract name should be equal.

Rename contract file from test.sol to TestAuction.sol and run it.

• Tried and the error is the same. I did js version of test successfully and want to do the same with solidity. – user938363 Aug 9 '18 at 8:05
• It would be more better if you can share your full code somewhere, I have tried to reproduce the issue with meta-coin truffle, but seems working fine – Div Aug 9 '18 at 8:26
• Added Auction.sol and 2_deploy_contracts.js to the post. Let me know if you want to see more file. Thanks. – user938363 Aug 9 '18 at 16:59
• @user938363, answer updated, please give a try with appropriate changes. – Div Aug 10 '18 at 5:12

Maybe you can try const Auction_sol = artifacts.require("Auction");

• The error is the same. – user938363 Aug 9 '18 at 8:05
• That is not a valid solidity code outside a contract. – Ismael Aug 10 '18 at 18:53