title: java.net.UnknownServiceException: CLEARTEXT communication to t.main.wedeep.com.cn not permitted by network security policy
body: <p>I got above error when i use mockhttpserver to test http request, the following code is how i create service.</p>
  <pre><code>   fun &lt;T&gt; getService(clazz: Class&lt;T&gt;): T {
          val client = OkHttpClient.Builder().addInterceptor(HeaderInterceptor()).addInterceptor(HttpLoggingInterceptor().apply { level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE })
                  .build()
          return Retrofit.Builder()
                  .baseUrl(mockWebServer.url(&quot;&quot;))
                  .client(client)
                  .addConverterFactory(GsonConverterFactory.create(GSON))
                  .build()
                  .create(clazz)
      }
  </code></pre>
  <p>This is my Test code.</p>
  <pre><code>@UninstallModules(HomePageDataModule::class)
  @HiltAndroidTest
  class TestHomePageViewModel {
  
  
      private lateinit var viewModel: HomePageViewModel
  
      @get:Rule
      var hiltRule = HiltAndroidRule(this)
  
      @Inject
      lateinit var cpd: CompositionDao
  
      @Inject
      lateinit var csd: CompositionsDao
  
      @Inject
      lateinit var hpds: HomePageDataSource
  
      @Inject
      lateinit var ss :HomePageService
  
      @Before
      fun init() {
          hiltRule.inject()
          viewModel = HomePageViewModel(HomeCompositionsRepository(cpd, csd, hpds, Util.GSON))
  
      }
  
  
  
  
  
      @Test
      fun testObserveHomeData() {
  
          val data = Util.getFileString(&quot;mainpage.json&quot;)
          val rr  = GSON.fromJson(data,Array&lt;HomePreviewView&gt;::class.java)
          println(rr)
          enqueueResponse(&quot;mainpage.json&quot;)
          runBlocking {
              val result = ss.getHomeData()
              Assert.assertNotEquals(rr.size,result.body()!!.size)
          }
  }
  </code></pre>
  <p><strong>Everything works smoothly on my app except running my unit test code.</strong>
  There is a similar <a href="https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted">problem</a> , but my issue has a little difference compare to that one.
  Plenty of ways from that similar question i have tried, but not work.</p>
  <p>PS: If the test code run on Junit4Test but not AndroidJunit4Test, it works properly. But now i need to exectue a integrate test. So this part of code need to be executed on AndroidJunit4Test</p>