Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from iamjosephmj/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjosephmj committed Jun 27, 2021
2 parents 06bd623 + 43f0c27 commit bac838d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 58 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,37 @@ class MainActivityTest {

```


#### `Raccoon TestRule`

You can define the testRule in this way:
```kotlin

// Seup raccoon stub
val raccoonTestRule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(ServiceClass::class)
.build()
)
}

// Setup activity testRule
private val activityTestRule = ActivityTestRule(MainActivity::class.java)

@get:Rule
val chain: RuleChain = RuleChain
/*
* Always give raccoon testrule before the activity testRule, because this can be helpfull
* if you app does an API call at the launch of an activity.
*/
.outerRule(raccoonTestRule)
.around(activityTestRule)

```



## Contribution, Issues or Future Ideas

If part of Raccoon is not working correctly be sure to file a Github issue. In the issue provide as
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {

dependencies {

implementation("com.github.iamjosephmj:Raccoon:${Dependencies.raccoon}")
implementation(project(mapOf("path" to ":raccoon")))
implementation("com.android.support:multidex:${Dependencies.multiDex}")
implementation("androidx.core:core-ktx:${Dependencies.coreKtx}")
implementation("androidx.appcompat:appcompat:${Dependencies.appcompat}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package me.iamjoseph.raccoonsample.parsingtest

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import me.iamjoseph.raccoonsample.parsingtest.helper.MockService
import me.iamjoseph.raccoon.core.stub.RaccoonStub
import me.iamjoseph.raccoon.core.stub.config.RaccoonConfig
import me.iamjoseph.raccoon.rules.RaccoonTestRule
import me.iamjoseph.raccoonsample.MainActivity
import org.junit.After
import org.junit.Before
import me.iamjoseph.raccoonsample.parsingtest.helper.MockService
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith


Expand All @@ -21,8 +21,8 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ParsingTest {

@Before
fun setup() {

private val raccoonTestRule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(MockService::class)
Expand All @@ -31,23 +31,19 @@ class ParsingTest {

}

private val activityTestRule = ActivityTestRule(MainActivity::class.java)

@get:Rule
val rule = ActivityTestRule(
MainActivity::class.java, false, false
)
val chain: RuleChain = RuleChain
.outerRule(raccoonTestRule)
.around(activityTestRule)


@Test
fun useAppContext() {
rule.launchActivity(null)
Thread.sleep(5000)
// Context of the app under test.
assert(true)
rule.activity.finish()
}

@After
fun tearDown() {
RaccoonStub.tearDown()
}

}
5 changes: 3 additions & 2 deletions raccoon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation("com.squareup.moshi:moshi:${Dependencies.moshi}")
kapt("com.squareup.moshi:moshi-kotlin-codegen:${Dependencies.moshi}")
implementation("com.squareup.moshi:moshi-kotlin:${Dependencies.moshi}")
implementation("junit:junit:${Dependencies.raccoonJunit}")
testImplementation("junit:junit:${Dependencies.raccoonJunit}")

}
Expand All @@ -57,15 +58,15 @@ afterEvaluate {
// You can then customize attributes of the publication as shown below.
groupId = 'com.iamjosephmj.raccoon'
artifactId = 'release'
version = '1.0.4'
version = '1.0.6'
}
// Creates a Maven publication called “debug”.
debug(MavenPublication) {
// Applies the component for the debug build variant.
from components.debug
groupId = 'com.iamjosephmj.raccoon'
artifactId = 'release'
version = '1.0.4'
version = '1.0.6'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.iamjoseph.raccoon.rules

import me.iamjoseph.raccoon.core.stub.RaccoonStub
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class RaccoonTestRule(
val setup: () -> Unit
) : TestRule {
override fun apply(base: Statement?, description: Description?): Statement {
return object : Statement() {
override fun evaluate() {

try {
setup.invoke()
base?.evaluate()
} catch (ex: Exception) {

} finally {
RaccoonStub.tearDown()
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import me.iamjoseph.raccoon.parser.GsonPlugin
import me.iamjoseph.raccoon.presentation.request.Parameters
import me.iamjoseph.raccoon.presentation.request.RaccoonRequest
import me.iamjoseph.raccoon.presentation.request.RaccoonRequestType
import me.iamjoseph.raccoon.rules.RaccoonTestRule
import org.junit.After
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test


Expand All @@ -22,8 +24,8 @@ class IncludeIntegrationTestsMoshi {
GsonPlugin()
}

@Before
fun setupStub() {
@get:Rule
val rule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(GsonServiceInclude::class)
Expand Down Expand Up @@ -213,11 +215,4 @@ class IncludeIntegrationTestsMoshi {
)
assertSame(response.parameters.headers[0].second, "{success}")
}


@After
fun cleanUp() {
RaccoonStub.tearDown()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import me.iamjoseph.raccoon.parser.MoshiPlugin
import me.iamjoseph.raccoon.presentation.request.Parameters
import me.iamjoseph.raccoon.presentation.request.RaccoonRequest
import me.iamjoseph.raccoon.presentation.request.RaccoonRequestType
import org.junit.After
import me.iamjoseph.raccoon.rules.RaccoonTestRule
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test


Expand All @@ -22,8 +22,8 @@ class IncludedIntegrationTestsGson {
MoshiPlugin()
}

@Before
fun setupStub() {
@get:Rule
val rule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(GsonServiceInclude::class)
Expand Down Expand Up @@ -237,11 +237,4 @@ class IncludedIntegrationTestsGson {

assertTrue(isExceptionOccurred)
}


@After
fun cleanUp() {
RaccoonStub.tearDown()
}

}
15 changes: 4 additions & 11 deletions raccoon/src/test/java/me/iamjoseph/raccoon/IntegrationTestsGson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import me.iamjoseph.raccoon.parser.GsonPlugin
import me.iamjoseph.raccoon.presentation.request.Parameters
import me.iamjoseph.raccoon.presentation.request.RaccoonRequest
import me.iamjoseph.raccoon.presentation.request.RaccoonRequestType
import org.junit.After
import me.iamjoseph.raccoon.rules.RaccoonTestRule
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test


Expand All @@ -22,8 +22,8 @@ class IntegrationTestsGson {
GsonPlugin()
}

@Before
fun setupStub() {
@get:Rule
val rule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(MockService::class)
Expand Down Expand Up @@ -213,11 +213,4 @@ class IntegrationTestsGson {
)
assertSame(response.parameters.headers[0].second, "{success}")
}


@After
fun cleanUp() {
RaccoonStub.tearDown()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import me.iamjoseph.raccoon.parser.MoshiPlugin
import me.iamjoseph.raccoon.presentation.request.Parameters
import me.iamjoseph.raccoon.presentation.request.RaccoonRequest
import me.iamjoseph.raccoon.presentation.request.RaccoonRequestType
import me.iamjoseph.raccoon.rules.RaccoonTestRule
import org.junit.After
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test


Expand All @@ -22,8 +23,8 @@ class IntegrationTestsMoshi {
MoshiPlugin()
}

@Before
fun setupStub() {
@get:Rule
val rule = RaccoonTestRule {
RaccoonStub.setUp(
RaccoonConfig.Builder()
.addService(MockService::class)
Expand Down Expand Up @@ -238,10 +239,4 @@ class IntegrationTestsMoshi {
assertTrue(isExceptionOccurred)
}


@After
fun cleanUp() {
RaccoonStub.tearDown()
}

}

0 comments on commit bac838d

Please sign in to comment.