Cannot resolve symbol testing in import statement - unit-testing

Getting error cannot resolve testing in my UnitTestClass
This my build dependency for test:
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
// Optional -- Robolectric environment
// testImplementation 'androidx.test:core:1.0.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.1'
testImplementation ('com.squareup.assertj:assertj-android:1.0.0') {
exclude module: 'support-annotations'
}
debugImplementation ('androidx.fragment:fragment-testing:1.2.5')
testImplementation 'androidx.test.ext:junit:1.1.1'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'androidx.arch.core:core-testing:2.1.0'
Also added this
testOptions {
unitTests {
includeAndroidResources = true
}
}

Add this to your dependencies
def fragment_version = "1.2.5"
debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
You can find more information in this link

Related

AndroidX ActionBar has disappeared: "Didn't find class "androidx.appcompat.app.ActionBar;" on path: DexPathList..."

Working on a fitness tracking app for portfolio using AndroidX dependencies, ran into the following error:
"E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.app.ActionBar;" on path: DexPathList..." (Full error pasted below).
My actionbar won't appear, so neither will my menu options. In researching this problem, I see it might be a dependencies issue, so my dependencies in module:app are...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// Room components
implementation 'androidx.room:room-runtime:2.0.0'
annotationProcessor 'androidx.room:room-compiler:2.0.0'
androidTestImplementation 'androidx.room:room-testing:2.0.0'
// Lifecycle components
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}
And in project...
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
roomVersion = '2.1.0-alpha06'
archLifecycleVersion = '2.1.0-alpha04'
}
Thank you in advance! If any other code would be helpful, I'll be happy to provide.
java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.app.ActionBar;" on path: DexPathList[[zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/base.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_dependencies_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_resources_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_0_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_1_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_2_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_3_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_4_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_5_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_6_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_7_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_8_apk.apk", zip file "/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:731)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/zachg.gsctrainingandnutritiontracker-CH8ZaSUoVNBUoZhkK4ObiA==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
... 12 more

Not able to import InstantTaskExecutorRule in my 'jUnit' test case even after adding 'core-testing' dependency - Android testing

I am writing test cases for my LoginViewModel. Where I want to perform setValue() operation on my MutableLiveData.
To avoid Method getMainLooper in android.os.Looper not mocked Exception I am trying to add the following Rule in my ViewModel file inside test folder.
#Rule
public InstantTaskExecutorRule mInstantTaskExecutorRule = new InstantTaskExecutorRule();
for that, I have added the following dependency:
androidTestImplementation 'android.arch.core:core-testing:1.1.1' as dependency.
But still, I am not able to import the InstantTaskExecutorRule in my LoginViewModelTest file. What could be the issue?
Though it's getting imported in androidTest folder where we write integration or UI test cases! But not in test folder where we write jUnit test cases!
Thank you in advance.
Please refer the build. gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.login"
minSdkVersion 19
targetSdkVersion 28
versionCode 2
versionName "1.1"
multiDexEnabled true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
testOptions {
unitTests.returnDefaultValues = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def design = "28.0.0"
implementation "com.android.support:appcompat-v7:$design"
implementation "com.android.support:design:$design"
implementation "com.android.support:recyclerview-v7:$design"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
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'
androidTestImplementation 'android.arch.core:core-testing:1.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.squareup.retrofit2:retrofit-mock:2.0.0'
implementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
def daggerVer = 2.16
implementation "com.google.dagger:dagger:$daggerVer"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVer"
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
//implementation 'com.google.android.material:material:1.0.0'
def lifeCycle = "1.1.1"
implementation "android.arch.lifecycle:extensions:$lifeCycle"
/*implementation "android.arch.lifecycle:runtime:$lifeCycle"
annotationProcessor "android.arch.lifecycle:compiler:$lifeCycle"*/
implementation "android.arch.persistence.room:runtime:$lifeCycle"
implementation 'com.mikhaellopez:circularimageview:3.2.0'
annotationProcessor
"android.arch.persistence.room:compiler:$lifeCycle"
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:multidex:1.0.3'
implementation 'commons-beanutils:commons-beanutils:1.9.3'
implementation 'org.mockito:mockito-core:2.23.4'
androidTestImplementation 'org.mockito:mockito-android:2.18.3'
}

java.lang.NoSuchMethodError: com.google.common.base.CharMatcher.whitespace()

I'm writing android unit tests with Robolectric. When I run my tests currently, I keep getting the above error.
I have looked at and tried tons of suggested solutions from here, but none of them have resolved this error.
So far I have looked at the dependency tree and I can see two versions of guava being used:
+--- com.google.guava:guava-jdk5:13.0#jar
+--- com.google.guava:guava:27.0.1-android#jar
After noticing this, I have then tried to:
exclude the first dependency
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.0.1'
classpath ('org.robolectric:robolectric:4.1') {
exclude group: 'com.google.guava', module: 'guava-jdk5'
}
}
}
upgrade the guava version to the latest
api 'com.google.guava:guava:27.0.1-android'
This is what the error looks like:
java.lang.NoSuchMethodError: com.google.common.base.CharMatcher.whitespace()Lcom/google/common/base/CharMatcher;
at org.robolectric.res.StringResources.processStringResources(StringResources.java:19)
at org.robolectric.res.StaxValueLoader.onEnd(StaxValueLoader.java:33)
at org.robolectric.res.StaxDocumentLoader.doParse(StaxDocumentLoader.java:66)
at org.robolectric.res.StaxDocumentLoader.loadResourceXmlFile(StaxDocumentLoader.java:30)
at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:48)
at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:27)
at org.robolectric.res.ResourceTableFactory.parseResourceFiles(ResourceTableFactory.java:149)
at org.robolectric.res.ResourceTableFactory.lambda$newFrameworkResourceTable$0(ResourceTableFactory.java:26)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:50)
at org.robolectric.res.ResourceTableFactory.newFrameworkResourceTable(ResourceTableFactory.java:12)
at org.robolectric.internal.SdkEnvironment.getSystemResourceTable(SdkEnvironment.java:35)
at org.robolectric.ApkLoader.getSystemResourceTable(ApkLoader.java:32)
at org.robolectric.android.internal.ParallelUniverse.injectResourceStuffForLegacy(ParallelUniverse.java:252)
at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:379)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:252)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
And this is my Test class currently:
#RunWith(RobolectricTestRunner.class)
public class MyTestClass {
MyTestFragment myTestFragment;
#Test
public void fragmentIsNotNull() throws Exception{
myTestFragment = MyTestFragment.newInstance();
assertNotNull(myTestFragment);
}
}
I would appreciate any help with this.
Thanks.
I have finally been able to get this to work by following the answer given here on SO from someone with a similar problem.
The issue was two conflicting guava dependencies as I pointed above.
+--- com.google.guava:guava-jdk5:13.0#jar
+--- com.google.guava:guava:27.0.1-android#jar
This is what I had tried before, to exclude guava,
configurations {
all*.exclude group: 'com.google.guava', module:'guava-jdk5'
}
But the guava-jdk-5 dependency was still being maintained.
So I finally added this to my gradle file instead:
compile('com.google.guava:guava-jdk5:17.0') { force = true }
This is what finally solved the bug.

PowerMock fails with JerseyTest

We're writing unit tests for a Jersey Java REST service using PowerMock. We have to use PowerMock because we use numerous static methods in a legacy system. We're using PowerMock with EasyMock. Whenever we try to inherit from JerseyTest, the whole framework fails.
It's a gradle based project, and the pertinent build.gradle lines are below.
testCompile 'junit:junit:4.12'
testCompile group: 'org.easymock', name: 'easymock', version: '3.5.1'
testCompile group: 'org.easymock', name: 'easymockclassextension', version: '3.2'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.7.3'
testCompile group: 'org.powermock', name: 'powermock-api-easymock', version: '1.7.3'
We have a few EasyMock unit tests up and running, so we know our imports are working correctly. The problem is that since we're testing a Jersey web service, our unit tests inherit from JerseyTest. Writing a PowerMock unit test without inheriting from JerseyTest works fine. But when we try to inherit from JerseyTest, it all falls apart. Google failed us (apparently no one else who has written a Jersey web service has tried using PowerMock).
What we do is fairly straight-forward. This works:
#RunWith(PowerMockRunner.class)
public class PowerMockTest {
private final static String TARGET = "ourwebservice/";
#Test
public void testConfigurationGet() {
// do stuff, but no Jersey web service calls
}
}
Changing the class declaraction to inherit from JerseyTest, however:
public class PowerMockTest extends JerseyTest {
And we get a complete failure. We're using Eclipse as our IDE, and this is the error that displays in the JUnit window:
initializationError (0.000 s)
The Failure Trace window gives more details:
java.lang.VerifyError: Inconsistent stackmap frames at branch target 38
Exception Details:
Location:
com/ourcompany/ourproduct/rest/PowerMockTest.<init>()V #38: aload_1
Reason:
Type uninitializedThis (current frame, locals[1]) is not assignable to 'com/ourcompany/ourproduct/rest/PowerMockTest' (stack map, locals[1])
Current Frame:
bci: #24
flags: { flagThisUninit }
locals: { uninitializedThis, uninitializedThis, top, 'java/lang/Object' }
stack: { 'java/lang/Object', 'java/lang/Object' }
Stackmap Frame:
bci: #38
flags: { flagThisUninit }
locals: { uninitializedThis, 'com/ourcompany/ourproduct/rest/PowerMockTest' }
stack: { }
Bytecode:
0x0000000: 2a4c 1211 b800 1703 bd00 1912 1ab8 001e
0x0000010: b800 244e 2db2 0028 a500 0e2a 01c0 002a
0x0000020: b700 2ea7 0009 2bb7 0030 0157 a700 0301
0x0000030: 3a05 2ab8 0036 b1
Stackmap Table:
append_frame(#38,Object[#14])
chop_frame(#44,1)
same_frame(#47)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.getTestMethods(PowerMockJUnit44RunnerDelegateImpl.java:109)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:85)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.<init>(PowerMockJUnit49RunnerDelegateImpl.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:172)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:48)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:108)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:71)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:36)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
We can't even step into the method to debug it; it fails before that (note, the test doesn't even actually do anything yet; we're just trying to get things set up first).
Anyone have any idea what's going on? Do we have some sort of configuration error? Do we have to switch to Mockito?

Grails Unit Test Exception java.lang.Exception: No tests found matching grails test target pattern filter

I am just starting to learn Grails testing and I tried to write my first grails test.For this, I created a fresh grails project and created a controller named com.rahulserver.SomeController:
package com.rahulserver
class SomeController {
def index() { }
def someAction(){
}
}
When I created this controller, grails automatically created a com.rahulserver.SomeControllerSpec under test/unit folder.
Here is my SomeControllerSpec.groovy:
package com.rahulserver
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {#link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/
#TestFor(SomeController)
class SomeControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void testSomeAction() {
assert 1==1
}
}
When I right click this class, and run this test, I get following:
Testing started at 5:21 PM ...
|Loading Grails 2.4.3
|Configuring classpath
.
|Environment set to test
....................................
|Running without daemon...
..........................................
|Compiling 1 source files
.
|Running 1 unit test...|Running 1 unit test... 1 of 1
--Output from initializationError--
Failure: |
initializationError(org.junit.runner.manipulation.Filter)
|
java.lang.Exception: No tests found matching grails test target pattern filter from org.junit.runner.Request$1#1f0f9da5
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
No tests found matching grails test target pattern filter from org.junit.runner.Request$1#1f0f9da5
java.lang.Exception: No tests found matching grails test target pattern filter from org.junit.runner.Request$1#1f0f9da5
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
|Completed 1 unit test, 1 failed in 0m 0s
.Tests FAILED
|
- view reports in D:\115Labs\grailsunittestdemo\target\test-reports
Error |
Forked Grails VM exited with error
Process finished with exit code 1
So why is it failing?
EDIT
I am using grails 2.4.3
The unit tests are defined with Spock by default:
void testSomeAction() {
assert 1==1
}
Should be written as:
void "Test some action"() {
expect:
1==1
}
See http://spockframework.github.io/spock/docs/1.0/index.html