VHow do you decide what to cover with unit tests versus integration tests?
Sentido de la respuesta✓
Idioma2
Pregunta del entrevistadorTesting
Los entrevistadores de puestos de desarrollo y de QA quieren ver una mentalidad de calidad: piensas en lo que puede salir mal, en cuán probable es y en cómo encontrarlo pronto. Las herramientas importan menos que el razonamiento. Un candidato que explica por qué existe una prueba es más sólido que uno que nombra cinco frameworks.
Da cada respuesta en tres pasos: una definición breve, un ejemplo de un proyecto real y el trade-off. En testing casi toda regla tiene una excepción, y decirlo demuestra que has trabajado con un conjunto de pruebas real y no solo has leído sobre uno.
- ✓Palabras → expresiones → frases → conversación
- ✓Sentido de la respuesta
- ✓Idioma
Preguntas habituales y respuestas de ejemplo
What is the test pyramid, and why does it matter?
¿Qué es la pirámide de pruebas (test pyramid) y por qué importa?
Qué quiere oír el entrevistador. La idea de muchas pruebas rápidas en la base y pocas lentas en la cima, con el motivo: coste, velocidad y claridad de los fallos.
Respuesta de ejemplo en inglés para practicar en voz altaThe 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?
¿Cuál es la diferencia entre una prueba unitaria y una de integración, y cuándo usas un mock?
Qué quiere oír el entrevistador. Definiciones claras, una regla sobre qué sustituir con un mock y el riesgo de abusar de los mocks.
Respuesta de ejemplo en inglés para practicar en voz altaA 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?
¿Qué es un test inestable (flaky test) y cómo lo tratas?
Qué quiere oír el entrevistador. Causas típicas, un método para encontrar la causa real y una política que proteja al equipo de ignorar los fallos.
Respuesta de ejemplo en inglés para practicar en voz altaA 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?
¿Cómo gestionas los datos de prueba?
Qué quiere oír el entrevistador. Pruebas aisladas, creación de datos legible y atención a la privacidad cuando intervienen datos reales.
Respuesta de ejemplo en inglés para practicar en voz altaGood 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?
¿Qué es el desarrollo guiado por pruebas (TDD) y lo usas?
Qué quiere oír el entrevistador. El ciclo rojo, verde, refactorizar, ventajas reales y una visión honesta de dónde encaja y dónde no.
Respuesta de ejemplo en inglés para practicar en voz altaTDD 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.
Cómo pronunciar los términos clave
- mock
- mok (rima con «clock»)
- flaky
- fléi-ki
- regression
- ri-gré-shon
- fixture
- fíks-cher
- assertion
- a-sér-shon
- coverage
- káv-er-ich
- deterministic
- di-tér-mi-nís-tik
Frases útiles para responder
- I would test the behaviour, not the implementation.Probaría el comportamiento, no la implementación.
- First I write a failing test that reproduces the bug.Primero escribo una prueba que falla y reproduce el error.
- I would mock only what I do not control.Solo haría mock de lo que no controlo.
- What is the risk if this fails in production?¿Cuál es el riesgo si esto falla en producción?
- The test should fail for one reason only.La prueba debería fallar por una sola razón.
- I would make the test deterministic first.Primero haría que la prueba fuera determinista.
- That belongs in a unit test, not an end-to-end test.Eso pertenece a una prueba unitaria, no a una de extremo a extremo.
Errores habituales que debes evitar
- Citar "90 percent coverage" como prueba de calidad. La cobertura muestra qué líneas se ejecutaron, no si las pruebas comprueban algo útil. Di qué protegen tus pruebas.
- Decir "I made a test" o "I did a bug", calcos de «hice una prueba» y «hice un error». Las colocaciones habituales son "write a test", "run the tests", "find a bug" y "fix a bug". Apréndelas como bloques hechos.
- Describir el testing como «ir haciendo clic por la aplicación». Habla de riesgo, de automatización y de dónde encaja cada tipo de prueba.
- Echar la culpa a otros, por ejemplo "developers write bad code" o "QA is too slow". Una respuesta sólida muestra responsabilidad compartida sobre la calidad.
- Afirmar que pruebas todo. Nadie puede, así que explica cómo eliges: por riesgo, por impacto y por la frecuencia con que cambia el código.
Preguntas frecuentes
¿Necesito conocer un framework de pruebas concreto?
Nombra el que usaste, por ejemplo JUnit, pytest o Jest, y explica cómo estructuraste las pruebas con él. Conceptos como el aislamiento, los mocks y los datos de prueba son los mismos en todos los frameworks, y a los entrevistadores les importan más.
¿Cómo muestro una mentalidad de QA en una entrevista?
Habla de riesgo y de usuarios: qué podría salir mal, qué impacto tendría y cómo lo encontrarías pronto. Menciona casos límite, pruebas exploratorias e informes de errores claros con los pasos para reproducirlos. Una historia corta sobre un error que encontraste antes del lanzamiento funciona bien.
¿Qué hago si me piden escribir casos de prueba en el momento?
Piensa en voz alta y usa un orden sencillo: el caso normal, los valores límite, la entrada vacía o inválida y los casos de fallo. Decir las categorías en voz alta muestra estructura, aunque no tengas tiempo de escribir todos los casos.
Leer una respuesta no es lo mismo que decirla. Practica cada pregunta en voz alta y después compara el sentido y el idioma de tu propia respuesta.
Probar SpeakRole ↗