์๊ฐ
GitHub Copilot์ ํ ์คํธ๋ฅผ ๋น ๋ฅด๊ฒ ๊ฐ๋ฐํ๊ณ ์์ฐ์ฑ์ ํฅ์์ํค๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค. ์ด ๋ฌธ์์์๋ Copilot์ ์ฌ์ฉํ์ฌ ๋จ์ ๋ฐ ํตํฉ ํ ์คํธ๋ฅผ ๋ชจ๋ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค. Copilot์ ๊ธฐ๋ณธ ํจ์์ ๋ํ ํ ์คํธ๋ฅผ ์์ฑํ ๋ ์ ์ํ๋์ง๋ง ๋ณต์กํ ์๋๋ฆฌ์ค์๋ ์ข ๋ ์์ธํ ํ๋กฌํํธ์ ์ ๋ต์ด ํ์ํฉ๋๋ค. ์ด ๋ฌธ์์์๋ Copilot์ ์ฌ์ฉํ์ฌ ์์ ์ ๋ถ์ํ๊ณ ์ฝ๋ ์ ํ์ฑ์ ํ์ธํ๋ ์ค์ ์์ ๋ฅผ ์๋ดํฉ๋๋ค.
ํ์ ์กฐ๊ฑด
์์ํ๊ธฐ ์ ์ ๋ค์์ ์ํํด์ผ ํฉ๋๋ค.
- GitHub Copilot ๊ตฌ๋ ํ๋.
- Visual Studio, Visual Studio Code ๋๋ JetBrains IDE์ ๋๋ค.
- GitHub Copilot ํ์ฅ์ด IDE์ ์ค์น๋์ด ์์ต๋๋ค.
Copilot Chat๋ฅผ ์ฌ์ฉํ์ฌ ๋จ์ ํ ์คํธ ์์ฑ
์ด ์น์
์์๋ GitHub Copilot ์ฑํ
์ ์ฌ์ฉํ์ฌ Python ํด๋์ค์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์ดํด๋ด
๋๋ค. ์ด ์์ ์์๋ Copilot์ ์ฌ์ฉํ์ฌ ํด๋์ค BankAccount
์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค. Copilot์ ํ๋กฌํํธํ์ฌ ํ
์คํธ๋ฅผ ์์ฑํ๊ณ , ์คํํ๊ณ , ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
์์ ํด๋์ค: BankAccount
๊ณ์ ์ ์์ก์ ์
๊ธ, ์ธ์ถ ๋ฐ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ํฌํจํ๋ ํด๋์ค BankAccount
๋ถํฐ ์์ํด ๋ณด๊ฒ ์ต๋๋ค. GitHub ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ ํ์ผ bank_account.py
๋ฅผ ๋ง๋ค๊ณ Python์์ ๋ค์ BankAccount
ํด๋์ค๋ฅผ ์ถ๊ฐํฉ๋๋ค.
class BankAccount:
def __init__(self, initial_balance=0):
if initial_balance < 0:
raise ValueError("Initial balance cannot be negative.")
self.balance = initial_balance
def deposit(self, amount):
if amount <= 0:
raise ValueError("Deposit amount must be positive.")
self.balance += amount
def withdraw(self, amount):
if amount <= 0:
raise ValueError("Withdrawal amount must be positive.")
if amount > self.balance:
raise ValueError("Cannot withdraw more than the current balance.")
self.balance -= amount
def get_balance(self):
return self.balance
Copilot Chat๋ฅผ ์ฌ์ฉํ์ฌ ๋จ์ ํ ์คํธ ์์ฑ
Copilot์ ๋ค์ํ ์๋๋ฆฌ์ค๋ฅผ ํฌ๊ดํ๋ ํ
์คํธ๋ฅผ ์์ฑํ๋ผ๋ ์์ฒญ์ ๋ณด๋ผ ์ ์์ต๋๋ค. ์ต์์ ๊ฒฐ๊ณผ๋ฅผ ์ป์ผ๋ ค๋ฉด ํ
์คํธ ์๊ตฌ ์ฌํญ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช
ํฉ๋๋ค. ๋ค์์ BankAccount
ํด๋์ค์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ํ๋กฌํํธ ์์ ์
๋๋ค.
ํ๋กฌํํธ:Python์์ BankAccount() ํจ์์ ๋ํ ํฌ๊ด์ ์ธ ๋จ์ ํ ์คํธ ์ ํ๊ตฐ์ ๊ฐ๋ฐํฉ๋๋ค. ์์ง ์ฌ๋ก, ์์ธ ์ฒ๋ฆฌ ๋ฐ ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํฌํจํ์ฌ ๊ด๋ฒ์ํ ์๋๋ฆฌ์ค๋ฅผ ๋ค๋ฃจ๋ ์ฌ๋ฌ ํ ์คํธ ๋ฉ์๋๋ฅผ ์์ฑํฉ๋๋ค.
์ด ํ๋กฌํํธ๋ ๋ค์๊ณผ ๊ฐ์ ๋ช ๊ฐ์ง ์ค์ํ ์์ ์ ์ํํฉ๋๋ค.
- ๋ฒ์: Copilot์ด ๋ค์ํ ์ ์ฌ์ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ๋ค๋ฃจ๋ ๊ธฐ๋ณธ ํ ์คํธ ์ด์์ ์์ฑํ๋๋ก ํฌ๊ด์ ์ธ ๋จ์ ํ ์คํธ ์ ํ๊ตฐ์ ๋ช ์์ ์ผ๋ก ์์ฒญํฉ๋๋ค.
- ์๋๋ฆฌ์ค: ํ๋กฌํํธ๋ ํ
์คํธ์ ๋ค์์ ํฌํจํ๋๋ก ์ง์ ํฉ๋๋ค.
- ์์ง ์ฌ๋ก: ๊ฒฝ๊ณ ์กฐ๊ฑด ํ ์คํธ(์: ์๊ธ ๋๋ ์ธ์ถ์ ๋ํ ์์ ๊ฐ, ์ฌ์ฉ ๊ฐ๋ฅํ ์์ก๋ณด๋ค ๋ ๋ง์ด ์ธ์ถ).
- ์์ธ ์ฒ๋ฆฌ: ํน์ ์๋ชป๋ ์์ ์ด ๋ฐ์ํ ๋ ๋ฐ์ํด์ผ ํ๋ ์ค๋ฅ์ ๋ํ ํ ์คํธ(์: ์ฌ์ฉ ๊ฐ๋ฅํ ์์ก๋ณด๋ค ๋ ๋ง์ ๊ธ์ก์ ์ธ์ถํ๊ณ ์์ ๊ธ์ก์ ์ ๊ธ).
- ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ: ์ ๋ ฅ์ ์ ํจ์ฑ์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฒ์ฌํ๊ณ ๋ฉ์๋์์ ์ฒ๋ฆฌํ๋๋ก ํฉ๋๋ค.
Copilot์ ๋ค์๊ณผ ๊ฐ์ ์๋ต์ ์ ๊ณตํฉ๋๋ค.
import unittest
from bank_account import BankAccount
class TestBankAccount(unittest.TestCase):
def setUp(self):
self.account = BankAccount()
def test_initial_balance(self):
self.assertEqual(self.account.get_balance(), 0)
def test_deposit_positive_amount(self):
self.account.deposit(100)
self.assertEqual(self.account.get_balance(), 100)
def test_withdraw_within_balance(self):
self.account.deposit(100)
self.account.withdraw(50)
self.assertEqual(self.account.get_balance(), 50)
def test_deposit_negative_amount_raises_error(self):
with self.assertRaises(ValueError):
self.account.deposit(-100)
def test_withdraw_negative_amount_raises_error(self):
with self.assertRaises(ValueError):
self.account.withdraw(-50)
def test_withdraw_more_than_balance_raises_error(self):
self.account.deposit(100)
with self.assertRaises(ValueError):
self.account.withdraw(200)
def test_initial_balance_negative_raises_error(self):
with self.assertRaises(ValueError):
BankAccount(-100)
if __name__ == '__main__':
unittest.main()
ํ ์คํธ ์ฌ๋ก ์คํ
Copilot์์ ์์ฑ๋ ํ
์คํธ ๋๊ตฌ ๋ชจ์์๋ ํ๋กฌํํธ์ ์ง์ ๋ ๊ฐ ์๋๋ฆฌ์ค์ ๋ํ ํ
์คํธ ์ฌ๋ก๊ฐ ํฌํจ๋ฉ๋๋ค. BankAccount
ํด๋์ค์์ ๊ฐ ํจ์๋ ์๊ธ ๋ฐ ์ธ์ถ๊ณผ ๊ฐ์ ์ ํจํ ์์
๋ฟ๋ง ์๋๋ผ ์์ ๊ธ์ก ๋ฐ ์ฌ์ฉ ๊ฐ๋ฅํ ์์ก๋ณด๋ค ๋ ๋ง์ ์ธ์ถ ์๋์ ๊ฐ์ ์์ง ์ฌ๋ก๋ฅผ ํฌํจํ์ฌ ๋ค์ํ ์กฐ๊ฑด์ ๋ํด ํ
์คํธ๋ฉ๋๋ค.
Copilot์ด ํ
์คํธ ๋๊ตฌ ๋ชจ์์ ์์ฑํ๋ฉด ์ ํ์ผ test_bank_account.py
์ ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค. ํ
์คํธ๋ฅผ ์คํํ๋ ๋ฐฉ๋ฒ์ ๋ฌผ์ด๋ณผ ์ ์์ต๋๋ค.
ํ๋กฌํํธ:"unittest ํ๋ ์์ํฌ๋ฅผ ์ฌ์ฉํ์ฌ Python์์ ์ด๋ฌํ ๋จ์ ํ ์คํธ๋ฅผ ์คํํ๋ ค๋ฉด ์ด๋ป๊ฒ ํ๋์?"
Copilot์ ๋ค์ bash ๋ช ๋ น์ ์ ๊ณตํฉ๋๋ค.
python -m unittest test_bank_account.py
ํ
์คํธ๋ฅผ ์คํํ๋ฉด ํฐ๋ฏธ๋ ๋๋ IDE์ ์ถ๋ ฅ์ด ํ์๋ฉ๋๋ค. ๋ชจ๋ ํ
์คํธ๊ฐ ํต๊ณผํ๋ฉด BankAccount
ํด๋์ค๊ฐ ์์๋๋ก ์๋ํ๋์ง ํ์ ํ ์ ์์ต๋๋ค.
์ฌ๋์ ๋ช ๋ น
๋ํ Copilot์๊ฒ /tests
์ฌ๋์ ๋ช
๋ น์ ์ฌ์ฉํ์ฌ ์ ์ฒด ๋จ์ ํ
์คํธ ๋ชจ์์ ์์ฑํ๋ผ๋ ๋ฉ์์ง๋ฅผ ํ์ํ ์ ์์ต๋๋ค. IDE์ ํ์ฌ ํญ์ ํ์ผ์ด ์ด๋ ค ์๋์ง ํ์ธํ๊ณ Copilot์์ ํด๋น ํ์ผ์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ์์ฑํฉ๋๋ค. Copilot์์ ์์ฑํ๋ ํ
์คํธ๋ ๋ชจ๋ ์๋๋ฆฌ์ค๋ฅผ ๋ค๋ฃจ์ง ์์ ์ ์์ผ๋ฏ๋ก ์์ฑ๋ ์ฝ๋๋ฅผ ํญ์ ๊ฒํ ํ๊ณ ํ์ํ ์ ์๋ ์ถ๊ฐ ํ
์คํธ๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
ํ
Copilot์ ๋จ์ ํ ์คํธ์์ ์์ง ๋ค๋ฃจ์ง ์์ ์ฝ๋ ํ์ผ์ ๋ํ ํ ์คํธ๋ฅผ ์์ฑํ๋๋ก ์์ฒญํ๋ ๊ฒฝ์ฐ ํธ์ง๊ธฐ์์ ์ธ์ ํ ํญ์์ ํ๋ ์ด์์ ๊ธฐ์กด ํ ์คํธ ํ์ผ์ ์ด์ด ์ ์ฉํ ์ปจํ ์คํธ์ ํจ๊ป Copilot์ ์ ๊ณตํ ์ ์์ต๋๋ค. Copilot์ ์ฌ์ฉํ๋ ํ ์คํธ ํ๋ ์์ํฌ๋ฅผ ๋ณผ ์ ์์ผ๋ฉฐ ๊ธฐ์กด ํ ์คํธ์ ์ผ์นํ๋ ํ ์คํธ๋ฅผ ์์ฑํ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค.
Copilot์ ๋ค์๊ณผ ๊ฐ์ ๋จ์ ํ ์คํธ ์ ํ๊ตฐ์ ์์ฑํฉ๋๋ค.
import unittest
from bank_account import BankAccount
class TestBankAccount(unittest.TestCase):
def setUp(self):
self.account = BankAccount()
def test_initial_balance(self):
self.assertEqual(self.account.get_balance(), 0)
Copilot์ ์ฌ์ฉํ์ฌ ํตํฉ ํ ์คํธ ์์ฑ
ํตํฉ ํ
์คํธ๋ ๊ฒฐํฉ ์ ์์คํ
์ ๋ค์ํ ๊ตฌ์ฑ ์์๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํ๋์ง ํ์ธํ๋ ๋ฐ ํ์์ ์
๋๋ค. ์ด ์น์
์์๋ ์ธ๋ถ ์๋น์ค NotificationSystem
์์ ์ํธ ์์ฉ์ ํฌํจํ๊ณ ๋ชจ์ ํญ๋ชฉ์ ์ฌ์ฉํ์ฌ ์ค์ ์ฐ๊ฒฐ ์์ด๋ ์์คํ
๋์์ ํ
์คํธํ๋๋ก BankAccount
ํด๋์ค๋ฅผ ํ์ฅํฉ๋๋ค. ํตํฉ ํ
์คํธ์ ๋ชฉํ๋ BankAccount
ํด๋์ค์ NotificationSystem
์๋น์ค ๊ฐ์ ์ํธ ์์ฉ์ ํ์ธํ์ฌ ์ฌ๋ฐ๋ฅด๊ฒ ํจ๊ป ์๋ํ๋์ง ํ์ธํ๋ ๊ฒ์
๋๋ค.
์์ ํด๋์ค: Notification Services๊ฐ ์๋ BankAccount
์ฌ์ฉ์์๊ฒ ์๋ฆผ์ ๋ณด๋ด๋ NotificationSystem
์(๊ณผ) ๊ฐ์ ์ธ๋ถ ์๋น์ค์์ ์ํธ ์์ฉ์ ํฌํจํ๋๋ก BankAccount
ํด๋์ค๋ฅผ ์
๋ฐ์ดํธ ํด๋ณด๊ฒ ์ต๋๋ค. NotificationSystem
์ ํ
์คํธํด์ผ ํ๋ ํตํฉ์ ๋ํ๋
๋๋ค.
๋ค์ ์ฝ๋ ์กฐ๊ฐ์ ์ฌ์ฉํ์ฌ bank_account.py
ํ์ผ์ BankAccount
ํด๋์ค๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.
class BankAccount:
def __init__(self, initial_balance=0, notification_system=None):
if initial_balance < 0:
raise ValueError("Initial balance cannot be negative.")
self.balance = initial_balance
self.notification_system = notification_system
def deposit(self, amount):
if amount <= 0:
raise ValueError("Deposit amount must be positive.")
self.balance += amount
if self.notification_system:
self.notification_system.notify(f"Deposited {amount}, new balance: {self.balance}")
def withdraw(self, amount):
if amount <= 0:
raise ValueError("Withdrawal amount must be positive.")
if amount > self.balance:
raise ValueError("Cannot withdraw more than the current balance.")
self.balance -= amount
if self.notification_system:
self.notification_system.notify(f"Withdrew {amount}, new balance: {self.balance}")
def get_balance(self):
return self.balance
์ฌ๊ธฐ์๋ Copilot์ ๋ํ ์์ฒญ์ ์ธ๋ถํํ์ฌ BankAccount
ํด๋์ค์ ๋ํ ํตํฉ ํ
์คํธ๋ฅผ ๋ ์๊ณ ๊ด๋ฆฌํ๊ธฐ ์ฌ์ด ์กฐ๊ฐ์ผ๋ก ์์ฑํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด Copilot์์ ์ข ๋ ์ ํํ๊ณ ๊ด๋ จ ์๋ ํ
์คํธ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
ํ๋กฌํํธ:_ "BankAccount
ํด๋์ค์ deposit
ํจ์์ ๋ํ ํตํฉ ํ
์คํธ๋ฅผ ์์ฑํฉ๋๋ค. ๋ชจ์ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ NotificationSystem
์(๋ฅผ) ์๋ฎฌ๋ ์ด์
ํ๊ณ ์
๊ธ ํ์ ์ฌ๋ฐ๋ฅด๊ฒ ํธ์ถ๋๋์ง ํ์ธํฉ๋๋ค."_
์ด ํ๋กฌํํธ๋ ๋ค์๊ณผ ๊ฐ์ ๋ช ๊ฐ์ง ์ค์ํ ์์ ์ ์ํํฉ๋๋ค.
- ๋ฒ์: ๋จ์ ํ
์คํธ๊ฐ ์๋๋ผ
deposit
ํจ์์NotificationSystem
๊ฐ์ ์ํธ ์์ฉ์ ์ค์ ์ ๋๊ณ ํตํฉ ํ ์คํธ๋ฅผ ์ง์ ํฉ๋๋ค. - ๋ชจ์ ํญ๋ชฉ:
NotificationSystem
์ด(๊ฐ) ๋ชจ์ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฎฌ๋ ์ด์ ํ๋๋ก ๋ช ์์ ์ผ๋ก ์์ฒญํ์ฌ ์ค์ ๊ตฌํ์ ์์กดํ์ง ์๊ณ ์ธ๋ถ ์์คํ ๊ณผ์ ์ํธ ์์ฉ์ ํ ์คํธํฉ๋๋ค. - ํ์ธ: ํ๋กฌํํธ๋
NotificationSystem
์ด ์ ๊ธ ํ ์ฌ๋ฐ๋ฅด๊ฒ ํธ์ถ๋๋์ง ํ์ธํ์ฌ ๊ตฌ์ฑ ์์ ๊ฐ์ ํตํฉ์ด ์์๋๋ก ์๋ํ๋์ง ํ์ธํฉ๋๋ค. - ํน์ด์ฑ: ํ๋กฌํํธ๋ ํ
์คํธํ ๋ฉ์๋(
deposit
) ๋ฐ ํด๋์ค(BankAccount
)๋ฅผ ๋ช ํํ๊ฒ ํ์ํฉ๋๋ค.
ํ
Copilot์ด ์๋ชป๋ ํ ์คํธ๋ฅผ ์์ฑํ๋ ๊ฒฝ์ฐ ํ ์คํธํ๋ ค๋ ํจ์์ ๋ํ ์ ๋ ฅ ๋ฐ ์ถ๋ ฅ์ ์๋ฅผ ์ ๊ณตํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด Copilot์ด ํจ์์ ์์ ๋์์ ํ๊ฐํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
Copilot์ ๋ค์๊ณผ ๊ฐ์ ํ ์คํธ ์ ํ๊ตฐ์ ์์ฑํฉ๋๋ค.
import unittest
from unittest.mock import Mock
from bank_account import BankAccount
class TestBankAccountIntegration(unittest.TestCase):
def setUp(self):
self.notification_system = Mock()
def test_deposit_with_notification(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
account.deposit(50)
self.assertEqual(account.get_balance(), 150)
self.notification_system.notify.assert_called_once_with("Deposited 50, new balance: 150")
if __name__ == '__main__':
unittest.main()
์์ฑ๋ ์ฝ๋๋ฅผ ์ ํ์ผ test_bank_account_integration.py
์ ์ถ๊ฐํฉ๋๋ค.
ํ ์คํธ ์ฌ๋ก ๊ฐ์
์์ ํ๋กฌํํธ๋ NotificationSystem
์ด(๊ฐ) ์ ํจํ ์
๊ธ์ด ์ด๋ฃจ์ด์ง ๋ ํธ์ถ๋๋ ๊ฒ์ ํ์ธํ๋ ๋จ์ผ ํ
์คํธ ์ฌ๋ก๋ฅผ ์์ฑํ์ต๋๋ค. ๊ทธ๋ฌ๋ ์
๊ธ ์ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ๋ ๋ค๋ฃจ์ง ์์ต๋๋ค. ์ด๋ฌํ ์๋๋ฆฌ์ค์์๋ NotificationSystem
์(๋ฅผ) ํธ์ถํ๋ฉด ์ ๋ฉ๋๋ค. ์๋ชป๋ ์๊ธ์ ์ฒ๋ฆฌํ๋ ํ
์คํธ ์ฌ๋ก๋ฅผ ์ถ๊ฐํ๊ณ ์๋ฆผ ์์คํ
์ด ํธ๋ฆฌ๊ฑฐ๋์ง ์๋๋ก ํด์ผ ํฉ๋๋ค.
ํ๋กฌํํธ:"ํจ์๊ฐ ์ฌ๋ฐ๋ฅธ ์์ธ๋ฅผ ๋ฐ์์ํค๊ณ NotificationService
์ด(๊ฐ) ํธ์ถ๋์ง ์๋์ง ํ์ธํ๊ธฐ ์ํด ์๋ชป๋ ์
๊ธ ๊ธ์ก์ ๋ํ ํ
์คํธ ์ฌ๋ก๋ฅผ ์ถ๊ฐํฉ๋๋ค."
Copilot์ ๋ค์๊ณผ ๊ฐ์ ํ ์คํธ ์ฌ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
def test_deposit_negative_amount_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.deposit(0)
self.notification_system.notify.assert_not_called()
๊ฐ์ ์์ญ์ ๋ํ ์ง๋ฌธ
์ด์ ์๊ธ์ ๋ํ ํตํฉ ๊ธฐ๋ฅ์ ์ ํจ์ฑ์ ๊ฒ์ฌํ๊ธฐ ์ํด ํ ์คํธ ์ฌ๋ก๋ฅผ ์์ฑํ์ผ๋ฏ๋ก ํ ์คํธ ๋๊ตฌ ๋ชจ์ ๋ด์์ ํฅ์๋ ๊ธฐ๋ฅ์ ๊ฒ์ํ ์ ์๋ ์ข์ ๊ธฐํ์ ๋๋ค. ํ์ฌ ํ ์คํธ๊ฐ ์๋ํ๋ ๋์ Copilot์ ์ฝ๋ ๊ฒ์ฌ๋ฅผ ํ๊ฐํ๋ผ๋ ๋ฉ์์ง๋ฅผ ํ์ํ๊ณ ๊ฐ์ ์์ญ์ ์ ์ํ ์ ์์ต๋๋ค.
ํ๋กฌํํธ: "BankAccount
ํด๋์ค์ NotificationSystem
๊ฐ์ ํตํฉ์ ๋ํ ์ ์ฒด ๊ฒ์ฌ๋ฅผ ๋ณด์ฅํ๊ธฐ ์ํด ์ด๋ค ์ถ๊ฐ ํ
์คํธ๋ฅผ ํฌํจํด์ผ ํ๋์?"
์ด ์ง๋ฌธ์ผ๋ก Copilot์ ๋ฉ์์ง๋ฅผ ํ์ํ๋ฉด ๊ฐ๊ณผ๋์์ ์ ์๋ ๋๋ฝ๋ ํ ์คํธ ์ฌ๋ก๋ฅผ ์๋ณํ๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ ์ ํจํ๊ณ ์๋ชป๋ ์๊ธ์ ํ ์คํธํ๋ ๋์ ์์ง ์ธ์ถ ๊ธฐ๋ฅ์ ๋ค๋ฃจ์ง ์์์ต๋๋ค.
Copilot์ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฐ์ดํธ๋ ํ ์คํธ ์ ํ๊ตฐ์ ์์ฑํฉ๋๋ค.
์ ์ฒด ์์ฑ๋ ์ฝ๋ ์์ ๋ฅผ ํ์ฅํ๋ ค๋ฉด ํด๋ฆญ
import unittest
from unittest.mock import Mock
from bank_account import BankAccount
class TestBankAccountIntegration(unittest.TestCase):
def setUp(self):
self.notification_system = Mock()
def test_deposit_with_notification(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
account.deposit(50)
self.assertEqual(account.get_balance(), 150)
self.notification_system.notify.assert_called_once_with("Deposited 50, new balance: 150")
def test_deposit_negative_amount_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.deposit(-50)
self.notification_system.notify.assert_not_called()
def test_deposit_zero_amount_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.deposit(0)
self.notification_system.notify.assert_not_called()
def test_withdraw_with_notification(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
account.withdraw(30)
self.assertEqual(account.get_balance(), 70)
self.notification_system.notify.assert_called_once_with("Withdrew 30, new balance: 70")
def test_withdraw_exceeding_balance_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.withdraw(150)
self.notification_system.notify.assert_not_called()
def test_withdraw_negative_amount_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.withdraw(-30)
self.notification_system.notify.assert_not_called()
def test_withdraw_zero_amount_raises_error(self):
account = BankAccount(initial_balance=100, notification_system=self.notification_system)
with self.assertRaises(ValueError):
account.withdraw(0)
self.notification_system.notify.assert_not_called()
def test_initial_negative_balance_raises_error(self):
with self.assertRaises(ValueError):
BankAccount(initial_balance=-100, notification_system=self.notification_system)
if __name__ == '__main__':
unittest.main()
Copilot์ด ๋ง์กฑ๋์ ๋ง๊ฒ ํ ์คํธ ์ ํ๊ตฐ์ ์์ฑํ ํ์๋ ์๋ ๋ช ๋ น์ ์ฌ์ฉํ์ฌ ํ ์คํธ๋ฅผ ์คํํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํฉ๋๋ค.
python -m unittest test_bank_account_integration.py
Copilot Spaces๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ ์ ์ ๊ฐ์
Copilot Spaces๋ Copilot๋ฅผ ์ฌ์ฉํ์ฌ ์์ ๋ณ ์ปจํ ์คํธ๋ฅผ ๊ตฌ์ฑํ๊ณ ๊ณต์ ํ ์ ์๋ ๊ธฐ๋ฅ์ ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉ์๊ฐ ๋ฐ๋ ์ ์์ ๊ด๋ จ์ฑ์ ๊ฐ์ ํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค. Copilot์ ํ๋ก์ ํธ์ ๋ํ ๋ ๋ง์ ์ปจํ ์คํธ๋ฅผ ์ ๊ณตํ์ฌ ๋ ๋์ ํ ์คํธ ์ ์์ ๋ฐ์ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, ๋ค์๊ณผ ๊ฐ์ ํญ๋ชฉ์ ํฌํจํ๋ Space๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค.
- ํ
์คํธ ์ค์ธ ๋ชจ๋(์:
payments.js
) - ํ์ฌ ํ
์คํธ ๋๊ตฌ ๋ชจ์(์:
payments.test.js
) - ๋๋ฝ๋ ํญ๋ชฉ์ ๋ํ ํ ์คํธ ๊ฒ์ฌ ๋ณด๊ณ ์ ๋๋ ๋ฉ๋ชจ
์ด Space์์ Copilot์๊ฒ ๋ค์๊ณผ ๊ฐ์ ์ง๋ฌธํ ์ ์์ต๋๋ค.
payments.js
์ ๋ ผ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋กpayments.test.js
์์ ์ด๋ค ํ ์คํธ ์ฌ๋ก๊ฐ ๋๋ฝ๋์์ด?
๋๋
๊ธฐ์กด ํ ์คํธ ๋๊ตฌ ๋ชจ์์ ๊ตฌ์กฐ๋ฅผ ๋ฐ๋ฅด๋ฉด์
refund.js
์ ํ๋ถ ๋ ผ๋ฆฌ์ ๋ํ ๋จ์ ํ ์คํธ๋ฅผ ์์ฑํด์ค.
Copilot Spaces ์ฌ์ฉ์ ๋ํ ์์ธํ ๋ด์ฉ์ About organizing and sharing context with GitHub Copilot Spaces์(๋ฅผ) ์ฐธ์กฐํ์ธ์.