S
stikker
Neues Mitglied
- 2
Hallo Leute,
da ich ab und an einfach mal ein paar Funktionen mit Konsolenausgabe testen will, weil es schneller geht, brauche ich die ExampleUnitTest.
Habe schon einiges versucht, aber irgendwie gibt er mir nicht die Werte aus der String.xml aus.
Im build.gradle habe ich folgendes stehen
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.powermock
owermock:1.6.5"
}
build.gradle(app)
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.13.1'
// Optional -- Robolectric environment
testImplementation 'androidx.test:core:1.0.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
}
mein Code in ExampleUnitTest
public class ExampleUnitTest {
@before
public void setup(){
MockitoAnnotations.initMocks(this);
}
@mock
Context mockContext;
@test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
System.out.println("hallo "+mockContext.getString(R.string.app_name));
}
}
Und trotzdem kommt der Wert "null" raus und nicht der app_name
Was fehlt bzw. was muss ich ändern, damit das klappt ?
Kann man über der TestKosole auch eine SQLite Datenbank erstellen lassen und darauf zugreifen ?
Danke
da ich ab und an einfach mal ein paar Funktionen mit Konsolenausgabe testen will, weil es schneller geht, brauche ich die ExampleUnitTest.
Habe schon einiges versucht, aber irgendwie gibt er mir nicht die Werte aus der String.xml aus.
Im build.gradle habe ich folgendes stehen
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.powermock

}
build.gradle(app)
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.13.1'
// Optional -- Robolectric environment
testImplementation 'androidx.test:core:1.0.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
}
mein Code in ExampleUnitTest
public class ExampleUnitTest {
@before
public void setup(){
MockitoAnnotations.initMocks(this);
}
@mock
Context mockContext;
@test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
System.out.println("hallo "+mockContext.getString(R.string.app_name));
}
}
Und trotzdem kommt der Wert "null" raus und nicht der app_name
Was fehlt bzw. was muss ich ändern, damit das klappt ?
Kann man über der TestKosole auch eine SQLite Datenbank erstellen lassen und darauf zugreifen ?
Danke