โครงร่างสถานการณ์และตารางข้อมูล
ขับเคลื่อนสถานการณ์ Gherkin เดียวด้วยชุดข้อมูลหลายชุด โดยใช้โครงร่างสถานการณ์ ตารางตัวอย่าง และตารางข้อมูลแบบแทรกในบรรทัด
โครงร่างสถานการณ์และตารางข้อมูล เป็นบทเรียน Testing Mastery: JUnit, Mockito & Integration Tests ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Testing Mastery: JUnit, Mockito & Integration Tests และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Testing Mastery: JUnit, Mockito & Integration Tests มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Repeating Scenarios
Often you want to run the same behavior with different inputs. Copy-pasting a scenario per case is wasteful. Gherkin's Scenario Outline parameterizes one scenario over many examples.
Placeholders with Angle Brackets
In a Scenario Outline, values are placeholders written in angle brackets, filled in from an Examples table.
Scenario Outline: add numbers
Given I enter <a> and <b>
When I add them
Then the result is <sum>The Examples Table
The Examples keyword introduces a table of rows. Each row runs the outline once with those values.
Examples:
| a | b | sum |
| 2 | 3 | 5 |
| 0 | 0 | 0 |
| 5 | 7 | 12 |How It Expands
Cucumber expands the outline into one concrete scenario per Examples row, substituting the placeholders. Three rows means three test runs.
Step Definition Receives Values
The step definition uses capture groups, and each expanded row supplies its values.
@Given("I enter {int} and {int}")
public void enter(int a, int b) {
this.a = a; this.b = b;
}Data Tables vs Outlines
An Examples table multiplies the scenario. A data table passes a structured argument to a single step.
Given the following users
| name | role |
| Ada | admin |
| Bob | guest |Consuming a Data Table
The step receives the table, which you can convert into a list of maps or domain objects.
@Given("the following users")
public void users(DataTable table) {
List<Map<String,String>> rows =
table.asMaps();
}Choosing the Right Tool
Use a Scenario Outline when the whole flow repeats with varied inputs. Use a data table when one step needs a collection of structured data.
Keeping Examples Readable
Name columns clearly and keep each Examples table focused. Large unfocused tables hide which behavior you are actually specifying.
Multiple Examples Blocks
You can have several Examples blocks under one outline, each with a tag or comment, to group happy-path and edge cases.
Why It Matters
Parameterized scenarios keep features concise and make boundary testing explicit and reviewable by non-developers.
Quick Check
What does each row of an Examples table produce?
Recap
You learned data-driven Gherkin:
- Scenario Outline uses
<placeholders>and an Examples table - Each row runs the scenario once
- Data tables pass structured data to a single step
- Pick outlines for repeated flows, data tables for collections
คำถามที่พบบ่อย
บทเรียน “โครงร่างสถานการณ์และตารางข้อมูล” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “โครงร่างสถานการณ์และตารางข้อมูล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Testing Mastery: JUnit, Mockito & Integration Tests ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Testing Mastery: JUnit, Mockito & Integration Tests มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “โครงร่างสถานการณ์และตารางข้อมูล”
ขับเคลื่อนสถานการณ์ Gherkin เดียวด้วยชุดข้อมูลหลายชุด โดยใช้โครงร่างสถานการณ์ ตารางตัวอย่าง และตารางข้อมูลแบบแทรกในบรรทัด คุณปฏิบัติ Testing Mastery: JUnit, Mockito & Integration Tests ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Testing Mastery: JUnit, Mockito & Integration Tests หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Testing Mastery: JUnit, Mockito & Integration Tests บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “โครงร่างสถานการณ์และตารางข้อมูล” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Testing Mastery: JUnit, Mockito & Integration Tests นี้ได้ไหม
ได้ บทเรียน Testing Mastery: JUnit, Mockito & Integration Tests ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ BDD
- ไวยากรณ์และฟีเจอร์ของ Gherkin
- การใช้งานคำจำกัดความของขั้นตอน
- โครงร่างสถานการณ์และตารางข้อมูล