I am trying to create a kotlin Multiplatform library which can later convert into java and javascript using IDEA 2019.3, kotlin 1.3 .
I created a simple junit (4) test class and configured it as follows.
package sample;
import org.junit.Test;
public class Tests {
#Test
public void test1(){
System.out.println("here");
}
}
But while running, it’s failing with
Process finished with exit code 1 Class not found: "sample.DummyTest"
I could not figure out what am I doing wrong. Please advice.
check your name of class test, it could be: com.package.example.Tests
or click right on your class and make the configuration:
if you want to run all test (included unitest from implements modules) in your project, create this configuration:
in your gradle dependencies check this import
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Related
Initially I was using Android Test Orchestrator in my app module. So I had this line in my build.gradle file:
dependencies {
androidTestUtil "androidx.test:orchestrator...`
...
}
However I am now moving to a test-only module. All of the androidTestImplementation keywords become just implementation. But what should I do for androidTestUtil? Should it become just util?
According to Android's documentation it should still be:
androidTestUtil 'androidx.test:orchestrator:x.x.x'
Just make sure you update
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
to
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
Credit: Android Test Orchestrator not working with Android X
I've been trying to use detox to test e2e.
RN 0.57.0
I followed the integration steps for android but I'm blocked on trying to compile the project.
detox build -c android.emu.debug
It builds perfectly when I run the normal ./gradlew assembleRelease command.
Note: there were 27 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Warning: android.support.test.espresso.core.internal.deps.guava.cache.Striped64: can't find referenced class sun.misc.Unsafe
...
Warning: android.support.test.espresso.core.internal.deps.guava.cache.Striped64$Cell: can't find referenced class sun.misc.Unsafe
Warning: android.support.test.espresso.core.internal.deps.guava.util.concurrent.AbstractFuture$UnsafeAtomicHelper: can't find referenced class sun.misc.Unsafe
...
Warning: android.support.test.espresso.core.internal.deps.guava.util.concurrent.AbstractFuture$UnsafeAtomicHelper$1: can't find referenced class sun.misc.Unsafe
Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer
Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
...
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning: there were 24 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 14 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForReleaseAndroidTest'.
> Job failed, see logs for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 30s
child_process.js:644
throw err;
^
Perhaps detox requires another proguard file?
----UPDATE----
Here is my build.gradle dependencies:
dependencies {
compile project(':rn-fetch-blob')
implementation project(':react-native-firebase')
implementation project(':react-native-image-resizer')
implementation project(':react-native-zendesk-support')
implementation project(':bugsnag-react-native')
implementation project(':react-native-fast-image')
implementation project(':react-native-calendar-events')
implementation project(':react-native-contacts')
implementation project(':react-native-device-info')
implementation project(':react-native-image-picker')
implementation project(':react-native-config')
implementation project(':react-native-restart')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.0"
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation "com.facebook.react:react-native:+" // From node_modules
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-analytics:15.0.2"
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3#aar') {
transitive = true;
}
implementation project(':react-native-photo-view')
implementation (project(':react-native-camera')) {
implementation 'com.android.support:exifinterface:27.1.0'
implementation ('com.google.android.gms:play-services-vision:15.0.1') {
force = true
}
}
implementation(project(':react-native-notifications')) {
exclude group: 'com.google.firebase', module: 'firebase-messaging'
}
implementation("com.google.firebase:firebase-messaging:15.0.2") {
implementation project(':react-native-notifications')
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
implementation project(':react-native-code-push')
androidTestImplementation(project(":detox"))
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
Not sure if the react native dependencies make a difference...
Perhaps there is a mismatch in versions?
I have a recycler view. In the adapter's onBindViewHolder method I have the following code to load an image:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Log.i("TEST-APP", "Binding View Holder")
Glide.with(context)
.load(items[position])
.placeholder(R.drawable.animated_loading_icon)
.into(holder.imageView)
}
However, Android Studio is saying that "placeholder" is an unresolved reference. This is confusing because the documentation indicates that this is the correct way to load a placeholder.
What am I doing wrong?
Also, here are my imports in the RecyclerViewAdapter class
package com.example.myname.recylerviewtest
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.*
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.recyclerview_item_column.view.*
Lastly, here are my dependencies in build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
api 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
As shown in the Glide documentation:
Most options in Glide can be applied using the RequestOptions class
and the apply() method.
Use request options to apply (among others):
Placeholders
Transformations
Caching Strategies
Component specific options, like encode quality, or decode Bitmap configurations.
So, if you want to use placeholder, you have two options.
One of them is to do it this way:
Glide.with(context)
.load(items[position])
.apply(RequestOptions()
.placeholder(R.drawable.animated_loading_icon)
)
.into(holder.imageView)
And the other option would be to implement the Generated API
I am very new to gradle and i am so confused in how to invoke my project so i can run my Cucumber test. What do i do after creating a build.gradle file?
my build.gradle looks like this
apply plugin: 'java'
dependencies {
testCompile 'info.cukes:cucumber-java:1.2.4'
testCompile 'info.cukes:cucumber-junit:1.2.4'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
project.ext {
cucumberVersion = '1.2.4'
junitVersion = '4.11'
}
test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
}
You create a JUnit class that uses a Cucumber runner to execute Cucumber.
#RunWith(Cucumber.class)
public class RunCukesTest {
}
in your test directory.
I describe it with more details here: http://www.thinkcode.se/blog/2015/01/30/bdd-with-cucumberjvm-at-geecon-tdd-2015
Another option is to start with the Java skeleton project that is available here: https://github.com/cucumber/cucumber-java-skeleton
And then follow the steps outlined in http://www.thinkcode.se/blog/2015/12/26/gradle-and-cucumberjvm
Just to extend Thomas's great answer I want to mention, that if your have your custom TestRunner class for specific suite of tests (like previously mentioned RunCukesTest or e.g. RegressionTestRunner), it is possible to add custom task for running the exact runner:
task runRegressionTests(type: Test) << {
include "RegressionTestRunner.class"
}
And then it is easy to run regression tests by gradle task:
gradle runRegressionTests
If you have a multiple runner classes for different suites (RegressionTestRunner, SanityTestRunner, etc) - it is useful to write a custom pattern for testing task which will recognize and run defined runner class.
E.g.:
runRegressionTests, runSanityTests.
Added the below in build.gradle file
test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
}
It invoked my cucumber test for gradle clean build
Use Gradle Cucumber JVM Plugin. It works perfectly and has pretty html reports integrated.
https://github.com/commercehub-oss/gradle-cucumber-jvm-plugin
This error means that class TestUtil is not on the classpath and the compiler can not find it. I came across such error hundred times before and there was missing Jar or wrong written class names, but now I just don't know what is wrong.
In my buildSrc dir I have custom Task and I made test for it:
package com.example.core.tasks;
import spock.lang.Specification
import org.gradle.api.Project
import org.gradle.util.TestUtil
public class GetInfoTaskTest extends Specification {
def "check files"(){
given:
def project = TestUtil.createRootProject()
when:
GetInfoTask getInfo = project.tasks.create("getInfo", GetInfoTask)
then:
getInfo instanceof GetInfoTask.class
}
}
In the build script in the buildSrc dir:
dependencies {
compile localGroovy()
testCompile 'org.spockframework:spock-core:0.7-groovy-1.8'
testCompile gradleApi()
}
Error:
GetInfoTaskTest.groovy: 4: unable to resolve class org.gradle.util.TestUtil
# line 3, column 1.
import org.gradle.util.TestUtil
^
I checked that this TestUtil is not internal. I still don't know why gradle can not find it.
TestUtil is an internal class. You can't use it in your own code.