首页 > > 详细

讲解 Task 5 - You Are the Auto Marker讲解 Python语言

Task 5 - You Are the Auto Marker (Literally)

Background

After proving yourself by fixing logic bugs in the banking tool, David has now assigned you to help write automated tests for the same codebase. In large organisations like Goldman Stanley, it's essential to catch bugs early through unit testing writing repeatable test functions that automatically verify that code behaves as expected. David has even given you full permissions on the Bloomberg testing terminal! Now your tests in test_task4.py will now show up in the auto marker section.

The development team has supplied you with a finished version of the BankAccount class. Your job is to write unit tests that verify all features work correctly and fail gracefully when given invalid input.

After putting your code from task 4 in. You should be able click the run tests and see the following:

The test case name is taken from the first line in the docstring. Please note that there are no automated marks associated with this task you are marked on the quality and coverage of your tests.

Description

You are again working on the BankAccount class. Your goal is to write a suite of unit tests that cover a wide range of normal and edge-case behaviours which will check your work from the previous task.

The file is not provided as it's the answer to the previous task but you're welcome to include your own code in the blank task4.py.

You must:

· Write test cases for each public method: deposit, withdraw, and transfer_to.

· Test for both correct and incorrect inputs.

· Use assertEqual, assertRaises, and (optionally) other assertions like assertIsInstance, assertGreaterEqual, etc.

· Organise your tests using a testing framework such as unittest.

Requirements

· Positive Cases:

o Check depositing and withdrawing valid amounts updates the balance correctly.

o Check transferring between two valid accounts works as expected.

o Check flagging / banning accounts prevents deposit/withdraw/transfer involving these accounts.

· ❌ Negative Cases:

o Check Deposit/withdraw/transfer with invalid types & values.

· �� Test Structure:

o Group related tests into test methods.

Remember, same as last task you should be using the errors from custom_errors.py

In order to be eligible to get full marks for this task you must make meaningful usage of the setup and teardown functionality provided in the unit test framework. More details here: https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass

Examples

A sample unit test has been provided within the scaffold.



联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!