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

tests for Android profiling #1949

Merged
merged 4 commits into from Mar 22, 2022

Conversation

stefanosiano
Copy link
Member

📜 Description

We added profiling to the android sdk. Now let's add tests!

💚 How did you test it?

Unit tests on everything touched by last pr

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

fixed few issues found via tests
@stefanosiano
Copy link
Member Author

I still need to add tests for AndroidTransactionProfiler (will be here by tomorrow, I think)
Other than that, i should have tested everything else (and found few details to fix, too)

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2022

Codecov Report

❗ No coverage uploaded for pull request base (feat/profiling/android@6a53471). Click here to learn what that means.
The diff coverage is n/a.

@@                    Coverage Diff                    @@
##             feat/profiling/android    #1949   +/-   ##
=========================================================
  Coverage                          ?   75.21%           
  Complexity                        ?     2279           
=========================================================
  Files                             ?      228           
  Lines                             ?     8167           
  Branches                          ?      873           
=========================================================
  Hits                              ?     6143           
  Misses                            ?     1605           
  Partials                          ?      419           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a53471...afda1be. Read the comment docs.

changed device_cpu_frequencies from List<String> -> List<Integer>
changed device_cpu_frequencies from List<String> -> List<Integer>
added changelog
@@ -41,7 +43,7 @@
private @Nullable File traceFile = null;
private @Nullable File traceFilesDir = null;
private @Nullable Future<?> scheduledFinish = null;
private volatile @Nullable ITransaction activeTransaction = null;
@VisibleForTesting volatile @Nullable ITransaction activeTransaction = null;
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 test the class without VisibleForTesting? I see this almost in every class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Avoiding it would make it harder/less readable to test the code without increasing the visibility of the field.
I realized that when using org.jetbrains.annotations.VisibleForTesting Android studio doesn't care whether you use it in tests or outside them, and builds in any case.
However, using androidx.annotation.VisibleForTesting makes Android studio complain if you access that field outside tests.
Of course, that would work in sentry-android-* only. Would it make any difference?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is that we could not use androidx.annotation in non-Android projects and that would make 2 different packages of annotations across the project, so we preferred to keep the standard.

You can configure AS to warn in such cases well.

You can also test the behavior of the method without using VisibleForTesting, for example, when you finish the transaction 2 times, you can verify that the captureTransaction method was called only once, so the activeTransaction was actually null during the 2nd time, instead of asserting the field directly.

Usually VisibleForTesting is only necessary when you are working with static fields or when its technically not possible to test the behaviour, it does not like this use case for this field.

@bruno-garcia
Copy link
Member

❗ No coverage uploaded for pull request base (feat/profiling/android@6a53471). Click here to learn what that means.

Odd that codecov didn't work

Replaced all over the project:
org.junit.Ignore -> kotlin.test.Ignore
org.junit.Before -> kotlin.test.BeforeTest
org.junit.After -> kotlin.test.AfterTest
@marandaneto marandaneto merged commit 2c1fe98 into feat/profiling/android Mar 22, 2022
@marandaneto marandaneto deleted the feat/profiling/android_tests branch March 22, 2022 12:09
stefanosiano added a commit that referenced this pull request Mar 31, 2022
stefanosiano added a commit that referenced this pull request Apr 1, 2022
stefanosiano added a commit that referenced this pull request Apr 1, 2022
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.

None yet

4 participants