Rafael Noronha

closing the gap between business and technology

Archive for the ‘Testes Automatizados’ tag

(Inglês) Database Integration Tests – implementing it

without comments

Este texto está disponível apenas em Inglês.

Written by rafanoronha

June 8th, 2010 at 12:10 am

(Inglês) Database Integration Tests – understanding it

without comments

Este texto está disponível apenas em Inglês.

Written by rafanoronha

May 3rd, 2010 at 9:48 pm

(Inglês) Database Integration Tests – considering it

without comments

Este texto está disponível apenas em Inglês.

Written by rafanoronha

April 19th, 2010 at 11:12 pm

(Inglês) TDD as a training method

with 2 comments

Este texto está disponível apenas em Inglês.

Written by rafanoronha

January 18th, 2010 at 10:02 pm

Teste dedo-duro

with one comment

Tem um colega de equipe que não dá pra confiar?
creisson
Seus problemas acabaram…

Teste dedo-duro


        [Test]
        public void controllers_wich_require_full_authentication()
        {
            var theseDoesNotRequire = new[] {
                typeof(AccountController),
                typeof(ErrorController),
                typeof(CustomController),
                typeof(HomeController)
            };

            foreach (var c in typeof(CustomController).Assembly.GetTypes()
                .Where(t => typeof(Controller).IsAssignableFrom(t)
                    && !theseDoesNotRequire.Contains(t)))
            {
                var attr = c.GetCustomAttributes(typeof(AuthorizeAttribute), false);
                Assert.IsTrue(attr.Length == 1);

                var authorize = attr[0] as AuthorizeAttribute;
                Assert.AreEqual(string.Empty, authorize.Roles);
                Assert.AreEqual(string.Empty, authorize.Users);
                Assert.AreEqual(-1, authorize.Order);
            }
        }

        [Test]
        public void all_controllers_should_inherit_custom_controller()
        {
            foreach (var c in typeof(CustomController).Assembly.GetTypes()
                .Where(t => typeof(Controller).IsAssignableFrom(t)
                    && t != typeof(CustomController)))
            {
                Assert.AreEqual(typeof(CustomController), c.BaseType);
            }
        }

        [Test]
        public void all_persisted_models_must_inherit_this_class()
        {
            foreach (Type type in typeof(WorkPeriod).Assembly.GetTypes()
                .Where(t => t.GetCustomAttributes(typeof(ActiveRecordAttribute), false)
                    .Count() > 0))
            {
                Assert.IsNotNull(type.BaseType);
                Assert.AreEqual(typeof(IdentifiedEntity<>), type.BaseType.GetGenericTypeDefinition());
            }
        }

Obs:

Provavelmente uma ferramenta legal para tratar este tipo de problema é um code analyser, como o FxCop.
Mas esta não deixa de ser uma opção bastante prática.

Sobre o colega incompetente, um pé na bunda é sempre a melhor solução (quando se trata daquele profissional que é ruim e não quer melhorar).

Independente da competência da equipe, é sempre bom automatizar este tipo de coisa!

Written by rafanoronha

July 14th, 2009 at 1:57 am