Todas as especialidadesTecnologia · Entrevista de emprego

Testes

As entrevistas sobre testes são sobre critério: o que testar, até que profundidade e o que fazer quando os testes não são fiáveis. Pratique estas respostas em voz alta, com uma estrutura clara.

Palavras → expressões → frases → fala

Experimentar o SpeakRole ↗
Entrevista de empregoTestes
V

How do you decide what to cover with unit tests versus integration tests?

0:18
Pergunta do entrevistador

Testes

Os entrevistadores de funções de programador e de QA querem ver uma mentalidade de qualidade: pensa no que pode correr mal, na probabilidade disso e na forma de o descobrir cedo. As ferramentas contam menos do que o raciocínio. Um candidato que explica porque existe um teste é mais forte do que quem nomeia cinco frameworks.

Dê cada resposta em três passos: uma definição curta, um exemplo de um projeto real e o compromisso. Nos testes, quase todas as regras têm exceção, e dizê-lo mostra que trabalhou com uma suite de testes real e não apenas leu sobre uma.

  • ✓Palavras → expressões → frases → fala
  • ✓Sentido da resposta
  • ✓Língua

Perguntas habituais e respostas de exemplo

What is the test pyramid, and why does it matter?

O que é a pirâmide de testes e porque é importante?

O que o entrevistador quer ouvir. A ideia de muitos testes rápidos na base e poucos lentos no topo, com a razão: custo, velocidade e clareza das falhas.

Resposta de exemplo em inglês para praticar em voz alta

The test pyramid is a model for balancing tests. At the bottom there are many fast unit tests, in the middle fewer integration tests, and at the top a small number of end-to-end tests through the real interface. The reason is cost. Unit tests run in milliseconds and point to the exact problem. End-to-end tests are slow, fragile and harder to debug, but they check that the whole system works. If a team has mostly end-to-end tests, the feedback is slow and the suite becomes unreliable. I use the pyramid as a guide, not as a law. For a service that is mostly integration with a database, I may write more integration tests.

What is the difference between a unit test and an integration test, and when do you use a mock?

Qual é a diferença entre um teste unitário e um teste de integração, e quando usa um mock?

O que o entrevistador quer ouvir. Definições claras, uma regra para o que substituir por um mock e o risco de usar mocks em excesso.

Resposta de exemplo em inglês para praticar em voz alta

A unit test checks one small piece of logic, like a function or a class, in isolation. It is fast and does not need a network or a database. An integration test checks that several parts work together, for example my code and a real database. I use a mock or a stub to replace a dependency that is slow, random or outside my control, like a payment gateway or the clock. But I do not mock everything. If a test only checks that my mock was called, it proves little and breaks whenever I refactor. For the database layer, I prefer a real database in a container, because it finds real problems, such as a wrong query.

What is a flaky test, and how do you deal with it?

O que é um teste instável (flaky) e como lida com ele?

O que o entrevistador quer ouvir. As causas típicas, um método para encontrar a causa real e uma política que proteja a equipa de falhas ignoradas.

Resposta de exemplo em inglês para praticar em voz alta

A flaky test sometimes passes and sometimes fails on the same code. It is dangerous, because people stop trusting the suite and start ignoring red builds. The common causes are fixed waiting times, shared state between tests, random or time-based data, and unstable external services. First I reproduce the problem, by running the test many times or in a different order, and I read the logs. Then I fix the cause: wait for a condition instead of sleeping, isolate the data, control the clock. If I cannot fix it quickly, I quarantine the test and create a ticket, so it does not block everyone. I never just add a retry and forget it.

How do you manage test data?

Como gere os dados de teste?

O que o entrevistador quer ouvir. Testes isolados, criação de dados legível e atenção à privacidade quando há dados reais envolvidos.

Resposta de exemplo em inglês para praticar em voz alta

Good test data is realistic, isolated and easy to understand. For unit tests, I create the data inside the test with small builders or factory functions, so the reader sees what matters. For integration and end-to-end tests, each test should create the data that it needs and clean up after itself, or run in a transaction that is rolled back, so tests do not depend on each other. I avoid sharing one big database dump, because nobody knows what is inside, and one change breaks many tests. I never copy real customer data into a test environment without anonymising it, because of privacy rules.

What is test-driven development, and do you use it?

O que é o desenvolvimento orientado por testes (TDD) e usa-o?

O que o entrevistador quer ouvir. O ciclo red, green, refactor, benefícios reais e uma visão honesta de onde se aplica e onde não.

Resposta de exemplo em inglês para praticar em voz alta

TDD means test-driven development. I write a failing test first, then the smallest amount of code that makes it pass, and then I refactor while the tests stay green. This is the red, green, refactor cycle. The benefit is that I think about the behaviour and the interface before the implementation, and I get a safety net for later changes. I find it most useful for business logic and for bug fixes: I first write a test that reproduces the bug. I use it less for exploratory work, like a new user interface, where I do not yet know what I am building. For me, it is a tool, not a rule.

Como pronunciar os termos-chave

mock
mók (rima com "clock")
flaky
flêi-ki
regression
ri-gré-chan
fixture
fíks-tcher
assertion
a-sér-chan
coverage
ká-ve-ridj
deterministic
di-tér-mi-nís-tik

Frases úteis para responder

  • I would test the behaviour, not the implementation.Eu testaria o comportamento, e não a implementação.
  • First I write a failing test that reproduces the bug.Primeiro escrevo um teste que falha e que reproduz o bug.
  • I would mock only what I do not control.Eu só faria mock do que não controlo.
  • What is the risk if this fails in production?Qual é o risco se isto falhar em produção?
  • The test should fail for one reason only.O teste só deve falhar por uma razão.
  • I would make the test deterministic first.Eu tornaria primeiro o teste determinístico.
  • That belongs in a unit test, not an end-to-end test.Isso pertence a um teste unitário, e não a um teste end-to-end.

Erros comuns a evitar

  • Citar "90 percent coverage" como prova de qualidade. A cobertura mostra que linhas foram executadas, e não se os testes verificam algo útil. Diga o que os seus testes protegem.
  • Dizer "I made a test" (decalque de «fiz um teste») ou "I did a bug". As colocações habituais são "write a test", "run the tests", "find a bug" e "fix a bug". Aprenda-as como blocos prontos.
  • Descrever os testes como "andar a clicar na aplicação". Fale de risco, de automação e de onde cabe cada tipo de teste.
  • Culpar os outros, por exemplo "developers write bad code" ou "QA is too slow". Uma resposta forte mostra responsabilidade partilhada pela qualidade.
  • Afirmar que testa tudo. Ninguém consegue, por isso explique como escolhe: pelo risco, pelo impacto e pela frequência com que o código muda.

Perguntas frequentes

Preciso de conhecer uma framework de testes específica?

Nomeie a que usou, por exemplo JUnit, pytest ou Jest, e explique como estruturou os testes com ela. Conceitos como isolamento, mocks e dados de teste são os mesmos em todas as frameworks, e os entrevistadores preocupam-se mais com eles.

Como mostro uma mentalidade de QA numa entrevista?

Fale de risco e de utilizadores: o que poderia correr mal, qual seria o impacto e como o descobriria cedo. Mencione casos-limite, testes exploratórios e relatórios de bugs claros, com passos para reproduzir. Uma história curta sobre um bug que encontrou antes do lançamento funciona bem.

E se me pedirem para escrever casos de teste na hora?

Pense em voz alta e use uma ordem simples: o caso normal, os valores-limite, a entrada vazia ou inválida e os casos de falha. Dizer as categorias em voz alta mostra estrutura, mesmo que não tenha tempo para escrever todos os casos.

Ler uma resposta não é o mesmo que dizê-la. Pratique cada pergunta em voz alta e depois compare o sentido e a língua da sua própria resposta.

Experimentar o SpeakRole ↗

Outros temas nesta área