Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test failure readability #18049

Merged
merged 5 commits into from
Dec 5, 2023

Conversation

ilmotta
Copy link
Contributor

@ilmotta ilmotta commented Dec 1, 2023

Summary

This PR is one of those you regret not opening before, way before. Problem: failed equality checks as in (is (= expected actual)) will give a single, long line of output that for anything but the simplest data structures is unreadable by humans, and the output doesn't give a useful diff. For me, unit testing so far in status-mobile has been one of the most insufferable experiences ever because of that alone.

The solution is simple: use library https://github.com/nubank/matcher-combinators which will define a directive match? which will pinpoint where two data structures differ. Then, instead of (is (= ..., use (is (match? expected actual). It works beautifully. No need to require any extra namespace, the directives are injected once in status-im.test-runner (false, in the CI the ClojureScript compiler couldn't find the match? directive).

Without this PR, if a test fails, I often had to copy the output, format it with zprint and diff two buffers and still manually scan the output hunting for a diff. It could be automated more, but it's just not worth it and it doesn't solve the problem for other devs.

Note

Guidelines were updated too: https://github.com/status-im/status-mobile/blob/ilmotta/improve-readability-of-test-failures/doc/new-guidelines.md#prefer-match-over--when-comparing-data-structures.

The library offers other nice matchers, but the majority of the time match? is sufficient.

Can we use another test runner like Kaocha?

kaocha-cljs2 would be able to print better test errors out of the box, among other features, but I have no clue if it would work well or at all in our stack (in theory yes, but it's a larger piece of work).

Demo

Areas that maybe impacted

None, just a few test namespaces were changed from using (is (= ...) to (is (match? ...)

status: ready

@status-im-auto
Copy link
Member

status-im-auto commented Dec 1, 2023

Jenkins Builds

Click to see older builds (11)
Commit #️⃣ Finished (UTC) Duration Platform Result
3366ffe #1 2023-12-01 16:13:48 ~3 min tests 📄log
✔️ 3366ffe #1 2023-12-01 16:17:15 ~6 min android 🤖apk 📲
✔️ 3366ffe #1 2023-12-01 16:17:19 ~6 min android-e2e 🤖apk 📲
✔️ 3366ffe #1 2023-12-01 16:18:14 ~7 min ios 📱ipa 📲
✔️ 92bd663 #2 2023-12-01 18:38:28 ~7 min android 🤖apk 📲
✔️ 92bd663 #2 2023-12-01 18:38:35 ~7 min android-e2e 🤖apk 📲
✔️ 92bd663 #2 2023-12-01 18:44:12 ~12 min ios 📱ipa 📲
✔️ 774f46e #3 2023-12-01 19:31:52 ~6 min android-e2e 🤖apk 📲
✔️ 774f46e #3 2023-12-01 19:36:55 ~11 min android 🤖apk 📲
✔️ 774f46e #3 2023-12-01 19:36:59 ~11 min tests 📄log
✔️ 774f46e #3 2023-12-01 19:38:20 ~13 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ e2adeb7 #4 2023-12-04 16:07:45 ~6 min android-e2e 🤖apk 📲
✔️ e2adeb7 #4 2023-12-04 16:09:06 ~7 min ios 📱ipa 📲
✔️ e2adeb7 #4 2023-12-04 16:11:24 ~9 min android 🤖apk 📲
✔️ e2adeb7 #4 2023-12-04 16:12:37 ~10 min tests 📄log
✔️ 47ec1be #5 2023-12-05 19:27:09 ~6 min android-e2e 🤖apk 📲
✔️ 47ec1be #5 2023-12-05 19:27:12 ~7 min android 🤖apk 📲
✔️ 47ec1be #5 2023-12-05 19:30:47 ~10 min tests 📄log
✔️ 47ec1be #5 2023-12-05 19:32:32 ~12 min ios 📱ipa 📲

Copy link
Member

@clauxx clauxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks great! Had to do the diffing manually once and it wasn't pleasant

@ilmotta ilmotta force-pushed the ilmotta/improve-readability-of-test-failures branch from 774f46e to e2adeb7 Compare December 4, 2023 16:01
Copy link
Member

@jakubgs jakubgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving only Nix related changes.

The namespace matcher-combinators.test must be required in namespaces using
"match?"
@ilmotta ilmotta force-pushed the ilmotta/improve-readability-of-test-failures branch from e2adeb7 to 47ec1be Compare December 5, 2023 19:19
@status-im-auto
Copy link
Member

77% of end-end tests have passed

Total executed tests: 48
Failed tests: 4
Expected to fail tests: 7
Passed tests: 37
IDs of failed tests: 702733,703133,702948,702869 
IDs of expected to fail tests: 702732,702894,702783,703503,702846,702731,702808 

Failed tests (4)

Click to expand
  • Rerun failed tests

  • Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_text_message_delete_push_disappear, id: 702733

    Device 1: Getting PN by 'DELETE ME'
    Device 2: Could not reach home view by pressing system back button

    critical/chats/test_1_1_public_chats.py:516: in test_1_1_chat_text_message_delete_push_disappear
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Deleted message is shown in chat view for 1-1 chat
    E    Deleted message is shown in chat view for 1-1 chat
    



    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_hashtag_links_to_community_channels, id: 702948

    Device 2: Find Text by xpath: //android.view.ViewGroup[@content-desc='chat-item']//android.widget.TextView[contains(@text,'#cats')]
    Device 2: Looking for a message by text: it is just a message text

    critical/chats/test_public_chat_browsing.py:1046: in test_community_hashtag_links_to_community_channels
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Receiver was not navigated to the cats channel
    E    Sender was not navigated to the cats channel
    



    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133

    Device 1: Tap on found: Button
    Device 1: Wait for element Button for max 30s and click when it is available

    critical/chats/test_public_chat_browsing.py:194: in test_restore_multiaccount_with_waku_backup_remove_switch
        self.sign_in.recover_access(passphrase=waku_user.seed, second_user=True)
    ../views/sign_in_view.py:276: in recover_access
        self.identifiers_button.wait_and_click(30)
    ../views/base_element.py:96: in wait_and_click
        self.wait_for_visibility_of_element(sec)
    ../views/base_element.py:139: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 1: Button by accessibility id:`skip-identifiers` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    2. test_community_undo_delete_message, id: 702869

    Device 1: Tap on found: Button
    Device 1: Looking for a message by text: message to delete and undo

    critical/chats/test_public_chat_browsing.py:113: in test_community_undo_delete_message
        self.channel.chat_element_by_text(message_to_delete).wait_for_visibility_of_element()
    ../views/base_element.py:139: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 1: ChatElementByText by xpath:`//*[starts-with(@text,'message to delete and undo')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']` is not found on the screen after wait_for_visibility_of_element
    
    During handling of the above exception, another exception occurred:
    critical/chats/test_public_chat_browsing.py:115: in test_community_undo_delete_message
        pytest.fail("Message was not restored by clicking 'Undo' button")
    E   Failed: Message was not restored by clicking 'Undo' button
    



    Device sessions

    Expected to fail tests (7)

    Click to expand

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_pin_messages, id: 702731

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Pin feature is in development]]

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_contact_block_unblock_offline, id: 702894

    Device 1: Find ProfileSendMessageButton by accessibility id: Chat-item-button
    Device 1: Sending message 'piy'

    critical/chats/test_public_chat_browsing.py:741: in test_community_contact_block_unblock_offline
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Chat with unblocked user was not enabled after 1 minute 
    

    [[Message can be missed after unblock: https://github.com//issues/16873]]

    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783

    Device 2: Find Text by xpath: //*[starts-with(@text,'test message')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']//*[@content-desc='message-status']/android.widget.TextView
    Device 2: Text is Sent

    critical/chats/test_1_1_public_chats.py:620: in test_1_1_chat_is_shown_message_sent_delivered_from_offline
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Message status was not changed to Delivered, it's Sent after back up online! 
    

    [[Data delivery issue]]

    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_community_discovery, id: 703503

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Curated communities not loading, https://github.com//issues/17852]]

    2. test_community_navigate_to_channel_when_relaunch, id: 702846

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Issue #18075]]

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Pin feature is in development]]

    2. test_group_chat_offline_pn, id: 702808

    Device 3: Looking for a message by text: message from old member
    Device 3: Looking for a message by text: message from new member

    critical/chats/test_group_chat.py:323: in test_group_chat_offline_pn
        self.errors.verify_no_errors()
    base_test_case.py:191: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Messages PN was not fetched from offline 
    

    [[Data delivery issue]]

    Device sessions

    Passed tests (37)

    Click to expand

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestDeepLinksOneDevice:

    1. test_links_open_universal_links_from_chat, id: 704613
    Device sessions

    2. test_links_open_universal_links_from_other_apps, id: 704614
    Device sessions

    3. test_links_deep_links, id: 702775
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    3. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    4. test_1_1_chat_edit_message, id: 702855
    Device sessions

    5. test_1_1_chat_send_image_save_and_share, id: 703391
    Device sessions

    6. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_message_delete, id: 702839
    Device sessions

    6. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    7. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844
    Device sessions

    8. test_community_message_edit, id: 702843
    Device sessions

    9. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_add_contact_field_validation, id: 702777
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    3. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_mentions_push_notification, id: 702786
    Device sessions

    3. test_community_leave, id: 702845
    Device sessions

    4. test_community_join_when_node_owner_offline, id: 703629
    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_mute_chat, id: 703495
    Device sessions

    2. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    3. test_group_chat_reactions, id: 703202
    Device sessions

    4. test_group_chat_join_send_text_messages_push, id: 702807
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    2. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    @ilmotta ilmotta merged commit 563f1c5 into develop Dec 5, 2023
    6 checks passed
    @ilmotta ilmotta deleted the ilmotta/improve-readability-of-test-failures branch December 5, 2023 20:20
    yevh-berdnyk pushed a commit that referenced this pull request Dec 8, 2023
    Problem: failed equality checks as in "(is (= expected actual))" will give a
    single, long line of output that for anything but the simplest data structures
    is unreadable by humans, and the output doesn't give a useful diff.
    
    Solution: use library https://github.com/nubank/matcher-combinators and its test
    directive "match?" which will pinpoint where two data structures differ. Then,
    instead of "(is (= ...", use "(is (match? expected actual)". It works
    beautifully.
    
    The library offers other nice matchers, but the majority of the time match? is
    sufficient.
    
    Can we use another test runner like Kaocha? kaocha-cljs2
    (https://github.com/lambdaisland/kaocha-cljs2) would be able to print better
    test errors out of the box, among other features, but I have no clue if it would
    work well or at all in our stack (in theory yes, but it's a larger piece of
    work).
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Archived in project
    Archived in project
    Development

    Successfully merging this pull request may close these issues.

    6 participants