-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add unit tests for
ParselyTracker
initialization
The `ParselyTracker#tearDown` method was added as singleton persisted between unit tests, causing some of them to fail. I could introduce a similar behavior using reflection, but I believe `internal tearDown` method is cleaner and is not problematic as not exposed to the client
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
parsely/src/test/java/com/parsely/parselyandroid/ParselyTrackerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import org.junit.After | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class ParselyTrackerTest { | ||
|
||
@Test(expected = ParselyNotInitializedException::class) | ||
fun `given no prior initialization, when executing a method, throw the exception`() { | ||
ParselyTracker.engagementIsActive() | ||
} | ||
|
||
@Test(expected = ParselyAlreadyInitializedException::class) | ||
fun `given prior initialization, when initializing, throw an exception`() { | ||
ParselyTracker.init(siteId = "", context = RuntimeEnvironment.getApplication()) | ||
|
||
ParselyTracker.init(siteId = "", context = RuntimeEnvironment.getApplication()) | ||
} | ||
|
||
@Test | ||
fun `given no prior initialization, when initializing, do not throw any exception`() { | ||
ParselyTracker.init(siteId = "", context = RuntimeEnvironment.getApplication()) | ||
} | ||
|
||
@Test | ||
fun `given tracker initialized, when calling a method, do not throw any exception`() { | ||
ParselyTracker.init(siteId = "", context = RuntimeEnvironment.getApplication()) | ||
|
||
ParselyTracker.engagementIsActive() | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
ParselyTracker.tearDown() | ||
} | ||
} |