Contenu connexe Similaire à TDD - Algumas lições aprendidas com o livro GOOS (20) TDD - Algumas lições aprendidas com o livro GOOS29. A mensagem de falha do teste expressa suficientemente bem o que está quebrado? 32. Elas ajudarão a diagnosticar problemas, quando novas features provoquem quebra de código existente. 37. Não se distraia com premissas que devem ser validadas em outros testes. 41. Se está interessado em criar um Domain Model, é importante separar classes de domínio das classes que possuem detalhes técnicos de como a funcionalidade é implementada. 49. Falhar o teste : o teste falha de forma clara, facilitando o correto diagnóstico? 53. Resta prover uma implementação do Delegate – um RestTemplateDelegate, por exemplo – e escrever um teste de integração. 54. Teste de Integração @RunWith (SpringJUnit4ClassRunner. class ) @ContextConfiguration (locations= "classpath:beans.xml" ) public class RestTemplateAuthenticatorTests { @Autowired private RestTemplateAuthenticationDelegate restTemplateDelegate ; private Authenticator authenticator ; @Before public void setup() { authenticator = new Authenticator( restTemplateDelegate ); } @Test public void authenticateUser() throws Exception { assertTrue ( authenticator .authenticate( "fab1@spam.la" , "teste123456" ).isAuthenticated()); } 55. RestTemplateAutenticationDelegate public class RestTemplateAuthenticationDelegate implements Authenticator.Delegate { private final String url ; private final RestTemplate rest ; public RestTemplateAuthenticationDelegate(String url, RestTemplate rest) { this . url = url; this . rest = rest; } public AuthenticationResponse performAuthentication(String username, String password) throws AuthenticationFailure { try { XmlAuthenticationRequest xmlRequest = new XmlAuthenticationRequest(); xmlRequest.setIp( "127.0.0.1" ); xmlRequest.setLogin(username); xmlRequest.setSenha(password); XmlAuthenticationResponse xmlResponse = rest .postForObject( url , xmlRequest, XmlAuthenticationResponse. class ); AuthenticationResponse response = new AuthenticationResponse(); response.setAuthenticated(xmlResponse.getStatus().equals( "AUTENTICADO" )); return response; } catch (Throwable e) { throw new AuthenticationFailure(e); } } } 58. Manter a cobertura dos testes em nível elevado (acima de 90%) é praticamente impossível se você não pratica Test First. 59. Aumentar a cobertura de código “Test After” é muito mais difícil, e pode dar um falsa sensação de cobertura. 64. Não é desejável que as mensagens críticas de logging quebrem com a evolução da aplicação 65. Caso existam ferramentas automáticas de análise de log, elas irão quebrar caso o logging não seja estável com o passar do tempo.