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

Adding unit tests to maestro-utils module #2081

Merged

Conversation

Matheeusb
Copy link
Contributor

@Matheeusb Matheeusb commented Oct 8, 2024

Proposed changes

  • Unit tests have been added for all classes in the maestro-utils module
  • After creating all tests, the module achieved 97% test coverage (code line)
  • 35 test scenarios were created

Captura de Tela 2024-10-11 às 11 06 30

copilot:summary

Testing

  • This PR is only about testing

Issues fixed

  • N/A

@Fishbowler
Copy link
Contributor

Those unit test failures are not yours - there's another PR that's going to fix those :D

@axelniklasson axelniklasson self-requested a review October 9, 2024 12:05
@axelniklasson axelniklasson self-assigned this Oct 9, 2024
@axelniklasson
Copy link
Contributor

Hey @Matheeusb -- thanks for raising this PR! I'll take a look at this throughout the week.

@Matheeusb
Copy link
Contributor Author

Thank you @axelniklasson !

val ip = SocketUtils.localIp()

assertNotNull(ip)
assertTrue(ip.startsWith("192") || ip.startsWith("10") || ip.startsWith("172"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This assertion fails for me when testing this locally as the IP resolves to 127.0.0.1 instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved here 08c9a16

}

@Test
fun `nextFreePort should throw IllegalStateException if no ports are available`() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rewrite this test to first use nextFreePort to find two suitable ports to use as from and to instead of hardcoding it? That way it won't clash with other processes running in the environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved here 08c9a16

Comment on lines 42 to 43
assertTrue(inetAddress is Inet4Address)
assertFalse(inetAddress.isLoopbackAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails if the returned address is a loopback address. What is the goal of this test? SocketUtils.localIp fallbacks to a loopback address so testing localIp should return a non-loopback IPv4 address doesn't really make sense to me so would love some context here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are sure @axelniklasson! I reviewed this test and saw that it does not bring any changes to test coverage. When creating this test, my objective was to validate that the connection returned was not of the loopback type, but in fact this validation makes no sense. I refactored the tests related to the localIp method, making the objectives of each test clearer and even achieving greater test coverage. You can check commit 0378f46

@axelniklasson
Copy link
Contributor

Will merge this after #2090 is merged

@axelniklasson axelniklasson force-pushed the feature/unit_test_maestro_utils branch from cb272ed to 4304529 Compare October 15, 2024 10:52
@axelniklasson axelniklasson merged commit 40b01f7 into mobile-dev-inc:main Oct 15, 2024
8 checks passed
@axelniklasson
Copy link
Contributor

Thanks for the contribution @Matheeusb 🎉

@Matheeusb Matheeusb deleted the feature/unit_test_maestro_utils branch October 15, 2024 14:38
rasyid7 pushed a commit to rasyid7/maestro that referenced this pull request Dec 9, 2024
* test: Adding unit tests to the MaestroTimerTest class

* test: Adding unit tests to the SocketUtils class

* test: Adding unit tests to the Strings class

* test: Adding unit tests to the Collections class

* test: Adding unit tests to the DepthTracker class

* test: Adding unit tests to the Insight class

* test: Adding unit tests to the Errors class

* test: Refactoring SocketUtils unit tests

* test: Resolving commands_optional_tournee test

* test: Refactoring test about localhost address

* test: Refactoring the tests about localIp method

* chore: Adding mockk dependency
rasyid7 pushed a commit to rasyid7/maestro that referenced this pull request Dec 9, 2024
* test: Adding unit tests to the MaestroTimerTest class

* test: Adding unit tests to the SocketUtils class

* test: Adding unit tests to the Strings class

* test: Adding unit tests to the Collections class

* test: Adding unit tests to the DepthTracker class

* test: Adding unit tests to the Insight class

* test: Adding unit tests to the Errors class

* test: Refactoring SocketUtils unit tests

* test: Resolving commands_optional_tournee test

* test: Refactoring test about localhost address

* test: Refactoring the tests about localIp method

* chore: Adding mockk dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants