I'm trying to learn and write best practice unittests and practice test driven design. Can you give me some tips and review my code?
using System.Threading.Tasks;
using Moq;
using Xunit;
namespace Blockchain.Unittests
{
public class AccountShould
{
private static string _webUrl = "https://test.test/test";
[Fact]
public async Task ReturnAccountBalance4EthWhenGivenAddress()
{
// Arrange
var address = AccountData.Address;
var web3RepositoryMock = new Mock<IWeb3Repository>();
web3RepositoryMock
.Setup(web3RepositoryMock => web3RepositoryMock.GetAccountBalanceInEth(It.IsAny<string>()))
.ReturnsAsync(4);
var account = new Account(web3RepositoryMock.Object);
// Act
var balance = await account.GetBalanceInEth(address);
// Assert
Assert.Equal(4, balance);
}
}
}
ClassA's functionality, which relies onClassB. We are mockingClassBin order to focus only onClassA's code by makingClassB's response deterministic and predictable. \$\endgroup\$accountStubis the mockedClassB. But you don't haveClassAin your test. \$\endgroup\$