2015-10-28 10 views
8

के लिए सही AssertThat विधि आयात करना मैं Robolectric.org के Writing Your First Test पृष्ठ से परीक्षण चलाने का प्रयास कर रहा हूं। सवाल में परीक्षण इस तरह दिखता है:Robolectric टेस्ट

@Test 
    public void clickingLogin_shouldStartLoginActivity() { 
    WelcomeActivity activity = Robolectric.setupActivity(WelcomeActivity.class); 
    activity.findViewById(R.id.login).performClick(); 

    Intent expectedIntent = new Intent(activity, WelcomeActivity.class); 
    assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent); 
    } 

मैं इस संकलन त्रुटि मिलती है: Cannot resolve method 'assertThat(android.content.Intent)

दो संभावनाएं मैं इस विधि आयात करने के लिए देख org.hamcrest.MatcherAssert.assertThat और org.junit.Assert.assertThat, जिनमें से न तो के रूप में इस Robolectric परीक्षण में इस्तेमाल किया जा रहा है एक एकल तर्क assertThat विधि होती है।

मेरे एप्लिकेशन की build.gradle इन निर्भरता है:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.1.0' 
    compile 'com.android.support:design:23.1.0' 

    testCompile "org.robolectric:robolectric:3.0" 
    testCompile 'junit:junit:4.12' 
} 

क्या ढांचे/पुस्तकालय इस परीक्षण का उपयोग कर रहा है?

+0

यह न तो 'junit' या' hamcrest' कथनों है Gradle पहली पंक्ति रखो। मुझे लगता है कि यह 'एंड्रॉइड एसेर्टजे' है या सिर्फ 'AssertJ' –

+0

तो यह था। धन्यवाद! अगर आप एक उत्तर पोस्ट करना चाहते हैं; मैं स्वीकार करूंगा – Michiyo

+0

आप दावे के लिए Google सत्य का भी उपयोग कर सकते हैं: https://github.com/google/truth –

उत्तर

16

यह न तो junit या hamcrest दावा API है। मुझे लगता है कि यह Android AssertJ या सिर्फ AssertJ है:

testCompile 'org.assertj:assertj-core:1.7.1' 
+0

ग्रेडल निर्भरता 'testCompile 'org.assertj: assertj-core: 1.7.1'' था। संस्करण 2 और 3 एंड्रॉइड के साथ संगत नहीं हैं। – Michiyo

+0

सही निर्भरता के साथ अद्यतन उत्तर। स्क्वायर –

+6

से एंड्रॉइड एसेर्टजे को भी देखें, यदि अच्छा है तो Robolectric ट्यूटोरियल StackOverflow के बजाय इसका उल्लेख करता है –

2

निम्नलिखित और इस मुद्दे को दूर जाना चाहिए का पालन करें। आप फ़ाइल का निर्माण

testCompile 'org.mockito:mockito-core:1.9.5' 
testCompile 'junit:junit:4.12' 

import org.junit.Test; 
import static org.hamcrest.CoreMatchers.is; 
import static org.hamcrest.MatcherAssert.assertThat; 

public class SomethingTest { 
    @Test 
    public void testSomething() { 
      assertThat(true, 1>1); 
    } 
} 

इस लिंक में अधिक जानकारी प्रदान करना चाहिए भी Android Studio and Robolectric

संबंधित मुद्दे