středa 5. listopadu 2014

nUnit - DataDriven Test

  1. Do testovací metody doplníme parametry.
  2. Metodu odekorujeme namísto atributu Test atributem TestCase který obsahuje parametry pro jedem testovací scénář.
  3. V metodě použijeme jednotlivé parametry jako vstupní parametry testu nebo jako očekávané výsledky testu.

[TestCase(123, "FVBAN", "BP14", "17Ř00U", Payment.PaymentMethodType.bank, "BAN")]
        [TestCase(-123, "BANFP", "BV14", "17Ř00P", Payment.PaymentMethodType.bank, "BAN")]
        [TestCase(123, "FVBAN", "PP", "17Ř00U", Payment.PaymentMethodType.payU, "PAYU")]
        [TestCase(-123, "POPLBAN", "PV", "17Ř00P", Payment.PaymentMethodType.payU, "PAYU")]
        public void Map_Payment_To_BankDokl(
            int amount,
            string predkont, 
            string rada, 
            string cleneni, 
            Payment.PaymentMethodType method, 
            string methodCode)
        {
            // Arange           
            var date = DateTime.Parse("2014-04-11");

            var payment = new Payment()
            {
                Amount = amount,
                ConstantSymbol = "12345",
                CounterpartAccountBank = "0100",
                CounterpartAccountNumber = "1212121212",
                Date = date,
                Description = "Karel nese čaj",
                PaymentMethod = method,
                SpecificSymbol = "123456999",
                VariableSymbol = "999999",
            };

            var bankDokl = new BankDokl();

            // Act
            AutoMapper.Mapper.Map(payment, bankDokl);

            // Assert
            Assert.AreEqual(Math.Abs(payment.Amount), bankDokl.Amount);
            Assert.AreEqual(payment.ConstantSymbol, bankDokl.ConstantSymbol);
            Assert.AreEqual(payment.CounterpartAccountNumber, bankDokl.Ucet.Ucet);
            Assert.AreEqual(payment.CounterpartAccountBank, bankDokl.Ucet.BKod);

            Assert.AreEqual(payment.Date, bankDokl.DatPlat);
            Assert.AreEqual(payment.Description, bankDokl.Note);
            Assert.AreEqual(methodCode, bankDokl.Ucet.Zkrat);
            Assert.AreEqual(payment.SpecificSymbol, bankDokl.SpecificSymbol);
            Assert.AreEqual(payment.VariableSymbol, bankDokl.VariableSymbol);

            Assert.AreEqual(rada, bankDokl.DRada);
            Assert.AreEqual(cleneni, bankDokl.Cleneni);
            Assert.AreEqual(predkont, bankDokl.PrKont);
        }

Zdroj:
http://www.nunit.org/index.php?p=testCase&r=2.5

Žádné komentáře:

Okomentovat