mercredi 23 décembre 2015

Unit Test is leaking implementation details

What are the best practices to avoid doing mistakes like leaking implementation details into unit tests?

An example is below and any help is much appreciated.

[TestMethod]
public void Add_Not_Important_Customer_With_Null_Parameters_Returns_False()
        {
            var customer = new Customer
            {
                DateOfBirth = DateTime.Now,
                EmailAddress = null,
                Firstname = null,
                Surname = null
            };

            Mock<CreditCheckNotImportantClientStrategy> _mockCreditCheckStrategy = new Mock<CreditCheckNotImportantClientStrategy>();
            _mockCreditCheckStrategy.Object.DoCreditCheck(_mockCreditService.Object, customer);

            _mockRepository.Setup(repo => repo.GetById(1)).Returns(new Company() { Id = 1 });

            _customerService = new CustomerService(_mockRepository.Object, _mockCreditCheckStrategy.Object, _mockCustomerDataAccess.Object, customer);

            customer.Company = _customerService.GetCompanyById(1);

            bool result = _customerService.AddCustomer(customer.Firstname, customer.Surname, customer.EmailAddress, customer.DateOfBirth, customer.Company.Id);
            Assert.IsFalse(result);
        }

Aucun commentaire:

Enregistrer un commentaire