add unit tests
This commit is contained in:
@@ -1,24 +1,18 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.lifecycle.Observer
|
||||
//import androidx.test.core.app.ApplicationProvider
|
||||
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||
import com.example.hpostesting.data.model.log.UploadLogsResponse
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.testing.SynchronousExecutor
|
||||
import androidx.work.testing.WorkManagerTestInitHelper
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.model.login.LoginResponse
|
||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
import com.example.hpostesting.domain.LogFileManager
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||
import com.example.hpostesting.util.TestCoroutineRule
|
||||
import com.google.common.base.Verify.verify
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
@@ -26,128 +20,22 @@ import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
import com.example.hpostesting.data.Result
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import androidx.work.Configuration
|
||||
//import androidx.work.testing.TestListenableWorkerBuilder
|
||||
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
class HemocubeViewModelTest {
|
||||
// @Mock
|
||||
// private lateinit var mockSharedPreferences: SharedPreferences
|
||||
//@RunWith(RobolectricTestRunner::class)
|
||||
//@Config(manifest = Config.NONE)
|
||||
//@ExperimentalCoroutinesApi
|
||||
//class HemocubeViewModelTest {
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockContext: Context
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var hemoCubeDaoMock: HemoCubeDao
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockRepository: Repository
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockHemoCubeBufferDao: HemoCubeBufferDao
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockLogFileManager: LogFileManager
|
||||
//
|
||||
// @Mock
|
||||
// private lateinit var mockLocalFileDataSource: LocalFileDataSource
|
||||
//
|
||||
// private lateinit var hemoCubeFragment: HemoCubeFragment
|
||||
//
|
||||
// private lateinit var hemoCubeViewModel: HemoCubeViewModel
|
||||
//
|
||||
// @Before
|
||||
// fun setUp() {
|
||||
// MockitoAnnotations.openMocks(this)
|
||||
// hemoCubeFragment = HemoCubeFragment()
|
||||
// Mockito.`when`(
|
||||
// mockSharedPreferences.getString(
|
||||
// ArgumentMatchers.anyString(),
|
||||
// ArgumentMatchers.anyString()
|
||||
// )
|
||||
// ).thenReturn("dummy_value")
|
||||
// hemoCubeViewModel = HemoCubeViewModel(hemoCubeDaoMock, mockHemoCubeBufferDao, mockRepository, mockLogFileManager, mockLocalFileDataSource, mockContext)
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `parseData test`() {
|
||||
// assertEquals(1, 1)
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `getCurrentDate returns date`() {
|
||||
//// `when`(hemoCubeViewModel.getCurrentDate()).thenReturn("1705429433")
|
||||
////
|
||||
//// val result = hemoCubeViewModel.getCurrentDate()
|
||||
////
|
||||
//// assertEquals("1705429433", hemoCubeViewModel.getCurrentDate())
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `extractMiddleString to get device id`() {
|
||||
// // Arrange
|
||||
// `when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
||||
//
|
||||
// // Act
|
||||
// val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
||||
//
|
||||
// // Assert
|
||||
// assertEquals("HPP1-9000", deviceId)
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `updateDeviceId in shared pref`() {
|
||||
// // Arrange
|
||||
// `when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("HPP1-0001")
|
||||
//
|
||||
// // Act
|
||||
// val deviceId = mockSharedPreferences.getString(anyString(), anyString())
|
||||
//
|
||||
// // Assert
|
||||
// assertEquals("HPP1-0001", deviceId)
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `allReadingsComplete check`() {
|
||||
// // Arrange
|
||||
// val repeatReadingCount = 1
|
||||
// val readingsPerSample = 1
|
||||
//
|
||||
// // Act
|
||||
// val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
||||
//
|
||||
// // Assert
|
||||
// assertEquals(true, result)
|
||||
// assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// @get:Rule
|
||||
// val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
//
|
||||
@@ -172,6 +60,13 @@ class HemocubeViewModelTest {
|
||||
// fun setup() {
|
||||
// MockKAnnotations.init(this)
|
||||
//
|
||||
// val config = Configuration.Builder()
|
||||
// .setMinimumLoggingLevel(android.util.Log.DEBUG)
|
||||
// .setExecutor(SynchronousExecutor())
|
||||
// .build()
|
||||
//
|
||||
// WorkManagerTestInitHelper.initializeTestWorkManager(context, config)
|
||||
//
|
||||
// every { context.getSharedPreferences(any(), any()) } returns mockk()
|
||||
//
|
||||
// viewModel = HemoCubeViewModel(
|
||||
@@ -192,15 +87,6 @@ class HemocubeViewModelTest {
|
||||
//
|
||||
// @Test
|
||||
// fun `login() should update LiveData with success`() = coroutineRule.runBlockingTest {
|
||||
// // Set up WorkManager with TestListenableWorkerBuilder
|
||||
// val config = Configuration.Builder()
|
||||
// .setMinimumLoggingLevel(android.util.Log.DEBUG)
|
||||
// .build()
|
||||
//
|
||||
// val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
//
|
||||
// WorkManagerTestInitHelper.initializeTestWorkManager(context, config)
|
||||
//
|
||||
//
|
||||
// // Arrange
|
||||
// coEvery { repository.login(any()) } returns Result.Success(mockk())
|
||||
@@ -255,4 +141,4 @@ class HemocubeViewModelTest {
|
||||
// // Assert
|
||||
// verify { observer.onChanged(response) }
|
||||
// }
|
||||
}
|
||||
//}
|
||||
Reference in New Issue
Block a user