---
# System prepended metadata

title: Testing in Hardhat v3

---

### Testing in Hardhat v3

**Introduction**

Hardhat is one of the most popular Ethereum development environments. With version 3, it introduces performance improvements and tighter integrations. Testing remains a core part of development, and Hardhat supports both JavaScript-based and Solidity-based testing.
**1. JavaScript Testing (Mocha + Chai)**

*Setup:*
Install Hardhat and dependencies:
```bash
npm install --save-dev hardhat
npm install --save-dev @nomicfoundation/hardhat-toolbox
```

*Sample Test (test/MyContract.js):*
```javascript
const { expect } = require("chai");

describe("MyContract", function () {
  it("Should deploy and return correct value", async function () {
    const Contract = await ethers.getContractFactory("MyContract");
    const contract = await Contract.deploy();
    await contract.deployed();

    expect(await contract.getValue()).to.equal(0);
  });
});
```

**2. Solidity Testing with Hardhat**

Hardhat also supports writing tests directly in Solidity using `hardhat/console.sol` and `foege-std/Test.sol` for debugging.

*Sample Solidity Test (contracts/MyTest.t.sol):*
```solidity
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "../contract/Counter.sol";
contract CounterTest is Test {
    Counter counter;

    function setUp() public {
        counter = new Counter();
    }

    function testIncrement() public {
        counter.increment();
        assertEq(counter.count(), 1);
    }
}
```

*4. Running Tests*

```bash
npx hardhat test
```


**Conclusion**

Hardhat v3 is still a solid choice with its JS and newly introduced Solidity Testing with provide flexibility. 