你如何获得一个Android上下文从一个Java项目JUnit测试的持有?上下文、如何获得、测试、项目

2023-09-07 16:46:45 作者:吃樱桃的小丸子

我需要为JUnit测试访问和Android方面。

I need to access and Android context for a JUnit Test.

我曾尝试使用MockContext和扩展AndroidTestCase但每次我得到一个错误说(存根!)

I have tried using MockContext and extending the AndroidTestCase but each time I get an error saying (stub!)

推荐答案

有关使用,而不是一个JUnit测试AndroidTestCase什么? AndroidTestCase将提供它需要的地方可以使用的getContext()上下文

What about using AndroidTestCase instead of a JUnit test? AndroidTestCase will provide a Context with getContext() that can be used where it's needed.