Testing Tdd Practice Exam
Question 1 of 50
sleep()
expect(render(<Button />)).toMatchSnapshot();
k6
export default function() {
http.get('https://api.example.com');
sleep(1);
}
Feature: User login
Scenario: Valid credentials
Given a registered user
When they enter valid credentials
Then they should see the dashboard
Feature
Scenario
Given
When
Then
And
But
test.each([
[1, 2, 3],
[0, 0, 0],
])('add(%i, %i) = %i', (a, b, expected) => {
expect(add(a, b)).toBe(expected);
});
@ParameterizedTest
@pytest.mark.parametrize
const spy = jest.spyOn(obj, 'method');
expect(spy).toHaveBeenCalledWith('arg');
describe('UserService', () => {
describe('createUser', () => {
test('creates with valid data', ...);
test('rejects invalid email', ...);
Playwright
Cypress
Selenium
+
-
==
!=
Stryker
PITest
mutmut
JMeter
Gatling
Locust
FakeUserRepository
HashMap
@Test
@BeforeEach
@AfterAll
@DisplayName
@Test void shouldAdd() {
assertEquals(5, calc.add(2, 3));
beforeEach
afterEach
String a = new String("hello");
String b = new String("hello");
assertEquals(a, b); // ✅ passes
assertSame(a, b); // ❌ fails (different objects)
toBe
toEqual
const dummyLogger = {} as Logger;
const service = new UserService(realRepo, dummyLogger);
dummyLogger
describe
it
Chai
Sinon
describe('Array', () => {
it('should return -1 when not found', () => {
assert.equal([1,2,3].indexOf(4), -1);
const mockFn = jest.fn().mockReturnValue(42);
Given a logged-in user
When they click "Delete Account"
Then their account is deactivated
// Arrange
const calc = new Calculator();
// Act
const result = calc.add(2, 3);
// Assert
expect(result).toBe(5);
Pact
Istanbul/nyc
coverage.py
JaCoCo
jest --retry 2
test('add returns sum', () => { expect(add(2, 3)).toBe(5); });
if (x > 0) { doA(); } else { doB(); }
x = 1
x = -1
Cucumber
SpecFlow
Given-When-Then
Behave
jest
pytest
gradle test
phpunit
go test
toBe(value)
toEqual(obj)
toContain(item)
toThrow()
toBeGreaterThan(n)
toMatch(/regex/)
getUser()
{ name: "Alice" }
beforeEach()
afterEach()
beforeAll()
afterAll()
beforeAll
afterAll
assert
def test_add():
assert add(2, 3) == 5
pytest -v
n
if
2^n
--coverage
describe('math', () => {
test('adds numbers', () => {
expect(1 + 2).toBe(3);
QuickCheck
Hypothesis
fast-check
reverse(reverse(list)) == list
Question navigator