Python เบื้องต้นสำหรับการทดสอบโค้ด
Alexander Levin
Data Scientist
ฟีเชอร์ (Feature)
ฟีเชอร์
Feature testing
Units:
Features:
Feature testing ช่วยให้:
ขอบเขตกว้างกว่า unit:
ในทางกลับกัน:
การตั้งค่าและกำหนดโค้ดฟีเชอร์:
# Setup
import pandas as pd
import pytest
df = pd.read_csv('laptops.csv')
# Filter feature
def filter_data_by_manuf(df, manufacturer_name):
filtered_df = df\
[df["Manufacturer"] == manufacturer_name]
return filtered_df
โค้ดทดสอบ:
# Feature test function
def test_unique():
manuf_name = 'Apple'
filtered = filter_data_by_manuf(df, manuf_name)
assert filtered\
['Manufacturer'].nunique() == 1
assert filtered\
['Manufacturer'].unique() == [manuf_name]
Feature testing — วิธีทดสอบซอฟต์แวร์เพื่อตรวจสอบพฤติกรรมของฟีเชอร์เฉพาะ
Features มีขอบเขตกว้างกว่า units:
Feature testing ช่วยให้ ผู้ใช้ได้รับสิ่งที่คาดหวังอย่างแท้จริง
การสร้าง feature tests ต้องออกแบบ test case ก่อน
กุญแจสำคัญในการออกแบบ feature tests — ต้องเข้าใจว่าฟีเชอร์ในระบบนั้นคืออะไร
Python เบื้องต้นสำหรับการทดสอบโค้ด