tanszek:oktatas:informacios_rendszerek_integralasa:tdd_pelda
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:informacios_rendszerek_integralasa:tdd_pelda [2024/02/25 22:03] – [Teszt vezérelt fejlesztés] knehez | tanszek:oktatas:informacios_rendszerek_integralasa:tdd_pelda [2024/02/25 22:32] (current) – [Teszt írása] knehez | ||
---|---|---|---|
Line 18: | Line 18: | ||
===== Teszt írása ====== | ===== Teszt írása ====== | ||
- | hozzunk létre egy // | + | hozzunk létre egy // |
+ | |||
+ | <sxh python> | ||
+ | def test_always_passes(): | ||
+ | assert True | ||
+ | |||
+ | def test_always_fails(): | ||
+ | assert False | ||
+ | </ | ||
+ | |||
+ | Majd futtassuk a tesztet: | ||
+ | python -m pytest tests | ||
+ | |||
+ | Hozzunk létre egy másik teszt fájlt, test_fixture.py: | ||
+ | |||
+ | <sxh python> | ||
+ | import pytest | ||
+ | |||
+ | @pytest.fixture | ||
+ | def example_fixture(): | ||
+ | return 1 | ||
+ | |||
+ | def test_with_fixture(example_fixture): | ||
+ | assert example_fixture == 1 | ||
+ | </ | ||
+ | |||
+ | A teszt futtatása után az alábbi eredményt kapjuk: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Javítsuk ki a tesztet | ||
+ | |||
+ | Hozzunk létre egy app alkönyvtárat a gyökérben és üres // | ||
+ | |||
+ | {{: | ||
+ | |||
+ | A test_data_formatter.py tartalma legyen: | ||
+ | |||
+ | <sxh python> | ||
+ | from app.data_formatter import format_data_for_display | ||
+ | def test_format_data_for_display(): | ||
+ | people = [ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | ] | ||
+ | |||
+ | assert format_data_for_display(people) == [ | ||
+ | " | ||
+ | "John Smith: Project Manager", | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | A data_formatter.py-ben megírjuk az implementációt: | ||
+ | <sxh python> | ||
+ | def format_data_for_display(people): | ||
+ | return [f" | ||
+ | </ | ||
+ | |||
+ | Futtassuk a tesztet: | ||
+ | python -m pytest tests |
tanszek/oktatas/informacios_rendszerek_integralasa/tdd_pelda.1708898599.txt.gz · Last modified: 2024/02/25 22:03 by knehez