🧪 測試改善:加入 GpxGenerator 空列表邊界情況測試#24
Conversation
🎯 What: - 新增 `GpxGeneratorTest` 測試類別 - 加入 `testGenerateGpx_emptyList` 測試,確保傳入空列表時不會崩潰且產生正確的基礎 GPX XML - 加入 `testGenerateGpx_withPoints` 作為 happy path 測試 📊 Coverage: - GpxGenerator.generateGpx 函數的正常流程與空列表邊界情況 ✨ Result: - 提升工具類別的測試覆蓋率,並避免未來可能的重構意外。 Co-authored-by: Max97k <14903047+Max97k@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces unit tests for the GpxGenerator utility, covering both empty lists and lists with location points. The feedback suggests improving the robustness of the assertions by splitting the generated XML into segments (such as metadata and track points) to verify that elements like session names, elevation, and timestamps are placed in their correct structural locations rather than relying on global string containment checks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| assertTrue("gpx close tag missing", result.contains("</gpx>")) | ||
|
|
||
| // Assert session name is in metadata and track | ||
| assertTrue("Session name missing", result.contains("<name>Empty Session</name>")) |
There was a problem hiding this comment.
這裡的測試註解提到「確認 session 名稱同時存在於 metadata 與 track 中」,但目前的斷言 result.contains("<name>Empty Session</name>") 只要該字串出現一次就會通過。如果未來不小心將 track 中的 <name> 移除,此測試仍會綠燈,無法有效防範迴歸(Regression)。
建議將 XML 內容拆分,並更精確地斷言 metadata 與 track 區段皆包含該名稱。
| assertTrue("Session name missing", result.contains("<name>Empty Session</name>")) | |
| val metadataSegment = result.substringAfter("<metadata>").substringBefore("</metadata>") | |
| val trkSegment = result.substringAfter("<trk>").substringBefore("</trk>") | |
| assertTrue("Session name missing in metadata", metadataSegment.contains("<name>Empty Session</name>")) | |
| assertTrue("Session name missing in track", trkSegment.contains("<name>Empty Session</name>")) |
| assertTrue("Latitude/longitude missing", result.contains("<trkpt lat=\"37.7749\" lon=\"-122.4194\">")) | ||
| assertTrue("Elevation missing", result.contains("<ele>10.0</ele>")) | ||
| assertTrue("Time missing", result.contains("<time>2021-01-01T00:00:00Z</time>")) |
There was a problem hiding this comment.
目前的斷言僅使用 contains 檢查全域字串,這可能導致結構錯誤(例如 <ele> 或 <time> 被誤放到 metadata 中,或者 track point 內缺少這些標籤)時測試依然通過。
建議精確地將 XML 拆分為 metadata 與 track point 區段,並分別驗證其內容,以確保 GPX 格式的正確性。
val metadataSegment = result.substringAfter("<metadata>").substringBefore("</metadata>")
val trkptSegment = result.substringAfter("<trkpt").substringBefore("</trkpt>")
assertTrue("Session name missing in metadata", metadataSegment.contains("<name>Test Session</name>"))
assertTrue("Time missing in metadata", metadataSegment.contains("<time>2021-01-01T00:00:00Z</time>"))
assertTrue("Latitude/longitude missing", result.contains("<trkpt lat=\"37.7749\" lon=\"-122.4194\">"))
assertTrue("Elevation missing in track point", trkptSegment.contains("<ele>10.0</ele>"))
assertTrue("Time missing in track point", trkptSegment.contains("<time>2021-01-01T00:00:00Z</time>"))|
Closed: duplicate, subsumed by #26 which has broader GpxGenerator test coverage |
🎯 What: The testing gap in
GpxGenerator.kthandling empty location lists.📊 Coverage: Added test cases covering both an empty list edge case and a happy path scenario with mock points.
✨ Result: Improved overall test coverage for GPX generation, making it more resilient.
PR created automatically by Jules for task 11267878584715082898 started by @Max97k