Espresso android -- 唤起断言? (不是视图断言)

Espresso android -- Evoke assert? (NOT a view assert)

我想做一个简单的测试。我只想要我的浓缩咖啡测试脚本来验证我没有在生产中。如果我 运行 在生产中购买,就会发生坏事,更不用说大量购买了。 我知道在 Java 中您需要将 -ae 添加到 运行 断言。这在 android 浓缩咖啡测试中似乎并不那么简单。我会将这段代码交给测试人员,所以如果它在生产中,我真的需要它失败。 (很明显,我会将其包装在 IF 中,但我希望它更丑陋——你搞砸了——有点像。)

public class PurchaseTest  extends BaseFooTest<HomeActivity> //ActivityInstrumentationTestCase2<LoginRegisterActivity>
{

final static String TAG = "PurchaseTest";
static final String PROD_URL = "https://api.foobar.com";
public PurchaseTest()
{
    super(HomeActivity.class);
}

public void test()
{

    System.out.println(fooApplication.hostUrl);
    assert fooApplication.hostUrl.equalsIgnoreCase(PROD_URL) == false;
    assert fooApplication.hostUrl.equalsIgnoreCase(PROD_URL) == true;
//       No assert! Not being read then!

}

///////////////////// 老板的代码,class 正在扩展,我认为这无关紧要,但是包含它,以防 extends basefootest 混淆了某人。

   public class BaseFooTest<T extends Activity> extends ActivityInstrumentationTestCase2
   {
   public BaseFooTest( Class<T> activityClass )
   {
       super( activityClass );
   }

   @Override
   public void setUp() throws Exception
   {
        super.setUp();
        getActivity();
        tryClickOk();
    }

    protected ViewAssertion isDisplayed()
    {
        return ViewAssertions.matches( ViewMatchers.isDisplayed() );
    }

    protected void tryClickOk()
    {
        try
        {
            onView( withText( "OK" ) ).perform( click() );
        }
        catch ( NoMatchingViewException e )
        {
        // Eat it
        // System.out.print( e );
        }

    }
}

possible to enable keyword asserts,但需要手动操作,而且在测试代码中使用关键字断言是不常见的。

最好像在单元测试中那样使用 JUnit 方法(assertTrue 等)。