Sobes.tech
Middle+

Provide an example of a unit test and an integration test for a deposit opening application. Do you see any risks in the approach where all types of tests are written by developers?

sobes.tech AI

Answer from AI

Unit test for deposit application:

def test_calculate_interest_for_deposit():
    deposit = Deposit(amount=10000, rate=0.05, term_months=12)
    interest = deposit.calculate_interest()
    assert interest == 500  # 10000 * 0.05

This test checks the correctness of interest calculation for a deposit without interaction with external systems.


Integration test:

def test_open_deposit_integration(client):
    response = client.post('/open_deposit', json={'user_id': 123, 'amount': 10000, 'term_months': 12})
    assert response.status_code == 200
    data = response.json()
    assert data['deposit_id'] is not None
    # Check that data is saved in the database
    deposit = db.get_deposit(data['deposit_id'])
    assert deposit.amount == 10000

This test checks the interaction between API, database, and business logic.


Risks if all tests are written by developers:

  • Reduced independence: Developers may unintentionally write tests that confirm their code rather than find errors.
  • Limited perspective: Lack of fresh QA perspective may lead to missing important scenarios and bugs.
  • Priorities: Developers may focus more on unit tests, neglecting integration and system tests.

To improve quality, it is advisable for QA specialists to participate in writing integration and system tests, while developers focus on unit tests.

Provide an example of a unit test and an integration… - sobes.tech