Issue
I want to run the setUp function only once, not before every test from the class. I've tried to make the setUp funtion static but i get an error - unresolved reference
@RunWith(AndroidJUnit4::class)
@LargeTest
open class BaseTest {
@Rule
val activityRule = ActivityTestRule(HomeActivity::class.java)
Class that inherits Base test class
@RunWith(AndroidJUnit4::class)
@LargeTest
open class HomeScreenWithoutInternet : BaseTest() {
private lateinit var context: HomeActivity
@Before
open fun setUp() {
context = activityRule.activity // "Unresolved reference: activityRule"
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifiManager.isWifiEnabled = false
TimeUnit.SECONDS.sleep(5)
assertFalse("There is internet connection available", isConnected(context))
}
Solution
Although it's recommended to keep tests completely independent from one another, there are things you just can't afford re-setting-up.
What you're looking for is @BeforeClass
(JUnit 4).
https://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall
Answered By - Achraf Amil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.