Giter Site home page Giter Site logo

oleaster's Introduction

RoboOleaster

Join the chat at https://gitter.im/bangarharshit/Oleaster Build Status

RoboOleaster is a BDD testing framework for Java and Android. It is a fork of Oleaster and is inspired heavily by Jasmine.

An Oleaster JUnit test looks like this:

@RunWith(OleasterRunner.class)
public class OleasterIntroductionTest {{
	describe("A suite", () -> {
		it("contains a spec with an expectation", () -> {
			expect(40 + 2).toEqual(42);
		});
	});
}}

Oleaster consists out of two independent libraries:

The Oleaster JUnit Runner gives you the option to write JUnit tests in the format shown above. Java 8 Lambda expressions are used to structure a test in suites and specifications.

Oleaster-Matcher provides Jasmine-like Matchers (expect(..).toEqual(..)) to validate test results. These Matchers can be used as a replacement (or extension) for standard JUnit assertions.

Documentation and examples

Oleaster JUnit Runner Documentation

Oleaster Matcher Documentation

Source of the AudioPlayer example from the Oleaster Runner documentation.

Oleaster tests are (mostly) written with Oleaster (see: Oleaster JUnit Runner Tests and Oleaster Matcher Tests).

Using RoboOleaster in your application

Add this in your root build.gradle

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Add this in your project build.gradle

// Main runner
testCompile 'com.github.OleasterFramework.Oleaster:oleaster-runner:v0.3.4'
// Robolectric support for Android
testCompile 'com.github.OleasterFramework.Oleaster:oleaster-robolectric:v0.3.4'
// For matchers
testCompile 'com.github.OleasterFramework.Oleaster:oleaster-matcher:v0.3.4'

Android Example

@RunWith(RoboOleaster.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class MainActivityTest {

    private MainActivity mainActivity;
    private Button nextActivityButton;

    {
        describe("Activity create", () -> {
            beforeEach(() -> {
                mainActivity = Robolectric.buildActivity(MainActivity.class).create().get();
                nextActivityButton = (Button) mainActivity.findViewById(R.id.next_activity_click);
            });
            it("the activity is created by setup", () -> {
                ShadowActivity shadowActivity = Shadows.shadowOf(mainActivity);

                Assert.assertFalse("Activity is just created", shadowActivity.isFinishing());
            });
            it("the activity is destroyed when finish is called", () -> {
                ShadowActivity shadowActivity = Shadows.shadowOf(mainActivity);
                mainActivity.finish();
                Assert.assertTrue("Activity is finished", shadowActivity.isFinishing());
            });
            it("the next activity is started when the next button is clicked", () -> {
                nextActivityButton.performClick();
                ShadowActivity shadowActivity = Shadows.shadowOf(mainActivity);
                Intent intent = shadowActivity.getNextStartedActivity();
                ShadowIntent shadowIntent = Shadows.shadowOf(intent);
                Assert.assertEquals(SecondActivity.class, shadowIntent.getIntentClass());
            });
        });
    }
}

Sample project can be found at RoboOleaster-Sample

Limitations

  1. No method level config support. We are exploring alternatives and is currently tracked here.
  2. Multiple API level support for a test. Check this issue.

Contributing to Oleaster

Check the issue tracker and send a PR. Looks for issues marked with good first issue label.

License

   Copyright (C) 2017 Harshit Bangar
   Copyright (C) 2017 Michael Scharhag
   Copyright (c) 2010 Xtreme Labs, Pivotal Labs and Google Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

oleaster's People

Contributors

bangarharshit avatar gitter-badger avatar harshitbangar123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

oleaster's Issues

Get current suite/test name at runtime

Copied from - mscharhag/oleaster#28

Thank you for the library, I am quite glad about it.
Unfortunately, I cannot 100% migrate my JUnit tests without hacks.

For some reasons, I need to get the current test name etc.
It would be great to expose some info at runtime.
While using JUnit, I used TestRules but they are not currently supported.

Support for multiple API levels in a test.

In Robolectric we can write:

@Config(sdk={21,22})
public class TestClass {
}

Oleaster defines a global config and picks the first of the level i.e. 21. Create local config to simulate test flow.

Method it() outputs the word "it" thus preventing clean localization

Copied from mscharhag/oleaster#26
If the method only echoed the descriptive string parameter the problem would be solved. Pretty sure Jasmine does it like this as well.

Not only for localization, also for flexibility in writing tests:

describe("The Product class", () -> {
    it("should be awesome", () -> {
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });
});

This now outputs as The Product class, it should be awesome. Which breaks the natural sentence imho. The Product class should be awesome wouldn't (arguably even without the comma)

API level 21 is not working due to incorrect shadows

Trace:

java.lang.NoSuchMethodError: java.lang.System.arraycopy([II[III)V
	at com.android.internal.util.GrowingArrayUtils.insert(GrowingArrayUtils.java:135)
	at android.util.SparseIntArray.put(SparseIntArray.java:143)
	at android.view.RenderNodeAnimator$1.__constructor__(RenderNodeAnimator.java:68)
	at android.view.RenderNodeAnimator$1.<init>(RenderNodeAnimator.java)
	at android.view.RenderNodeAnimator.__staticInitializer__(RenderNodeAnimator.java:67)
	at org.robolectric.util.ReflectionHelpers.callStaticMethod(ReflectionHelpers.java:263)
	at org.robolectric.internal.bytecode.RobolectricInternals.performStaticInitialization(RobolectricInternals.java:56)
	at org.robolectric.internal.bytecode.ShadowWrangler.classInitializing(ShadowWrangler.java:116)
	at org.robolectric.internal.bytecode.RobolectricInternals.classInitializing(RobolectricInternals.java:20)
	at android.view.RenderNodeAnimator.<clinit>(RenderNodeAnimator.java)
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:158)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:173)
	at org.robolectric.shadows.ShadowRenderNodeAnimator.reset(ShadowRenderNodeAnimator.java:33)
	at org.robolectric.Shadows.reset(Shadows.java:1662)
	at org.robolectric.Robolectric.reset(Robolectric.java:42)
	at org.robolectric.android.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:45)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.beforeTest(OleasterRobolectricRunner.java:104)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:273)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.RuntimeException: An exception occurred while running invokable: Can't create handler inside thread that has not called Looper.prepare()
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:168)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	... 21 more
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
	at android.os.Handler.__constructor__(Handler.java:200)
	at android.os.Handler.<init>(Handler.java)
	at android.app.Activity.__constructor__(Activity.java:793)
	at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
	at org.robolectric.internal.bytecode.ShadowImpl.invokeConstructor(ShadowImpl.java:71)
	at org.robolectric.shadow.api.Shadow.invokeConstructor(Shadow.java:66)
	at org.robolectric.shadows.ShadowActivity.__constructor__(ShadowActivity.java:80)
	at android.app.Activity.<init>(Activity.java)
	at com.example.harshitbangar.testapp.MainActivity.<init>(MainActivity.java:8)
	at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:322)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:98)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:94)
	at com.example.harshitbangar.testapp.MainActivityTest.lambda$null$0(MainActivityTest.java:35)
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:166)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	... 1 more
java.lang.NoClassDefFoundError: Could not initialize class android.view.RenderNodeAnimator
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
	at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
	at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
	at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
	at java.lang.reflect.Field.set(Field.java:764)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:158)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:173)
	at org.robolectric.shadows.ShadowRenderNodeAnimator.reset(ShadowRenderNodeAnimator.java:33)
	at org.robolectric.Shadows.reset(Shadows.java:1662)
	at org.robolectric.Robolectric.reset(Robolectric.java:42)
	at org.robolectric.android.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:45)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.beforeTest(OleasterRobolectricRunner.java:104)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:273)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.RuntimeException: An exception occurred while running invokable: Can't create handler inside thread that has not called Looper.prepare()
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:168)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	... 21 more
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
	at android.os.Handler.__constructor__(Handler.java:200)
	at android.os.Handler.<init>(Handler.java)
	at android.app.Activity.__constructor__(Activity.java:793)
	at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
	at org.robolectric.internal.bytecode.ShadowImpl.invokeConstructor(ShadowImpl.java:71)
	at org.robolectric.shadow.api.Shadow.invokeConstructor(Shadow.java:66)
	at org.robolectric.shadows.ShadowActivity.__constructor__(ShadowActivity.java:80)
	at android.app.Activity.<init>(Activity.java)
	at com.example.harshitbangar.testapp.MainActivity.<init>(MainActivity.java:8)
	at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:322)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:98)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:94)
	at com.example.harshitbangar.testapp.MainActivityTest.lambda$null$0(MainActivityTest.java:35)
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:166)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	... 1 more
java.lang.NoClassDefFoundError: Could not initialize class android.view.RenderNodeAnimator
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
	at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
	at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
	at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
	at java.lang.reflect.Field.set(Field.java:764)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:158)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:173)
	at org.robolectric.shadows.ShadowRenderNodeAnimator.reset(ShadowRenderNodeAnimator.java:33)
	at org.robolectric.Shadows.reset(Shadows.java:1662)
	at org.robolectric.Robolectric.reset(Robolectric.java:42)
	at org.robolectric.android.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:45)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.beforeTest(OleasterRobolectricRunner.java:104)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:273)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.RuntimeException: An exception occurred while running invokable: Can't create handler inside thread that has not called Looper.prepare()
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:168)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	... 21 more
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
	at android.os.Handler.__constructor__(Handler.java:200)
	at android.os.Handler.<init>(Handler.java)
	at android.app.Activity.__constructor__(Activity.java:793)
	at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
	at org.robolectric.internal.bytecode.ShadowImpl.invokeConstructor(ShadowImpl.java:71)
	at org.robolectric.shadow.api.Shadow.invokeConstructor(Shadow.java:66)
	at org.robolectric.shadows.ShadowActivity.__constructor__(ShadowActivity.java:80)
	at android.app.Activity.<init>(Activity.java)
	at com.example.harshitbangar.testapp.MainActivity.<init>(MainActivity.java:8)
	at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:322)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:98)
	at org.robolectric.Robolectric.buildActivity(Robolectric.java:94)
	at com.example.harshitbangar.testapp.MainActivityTest.lambda$null$0(MainActivityTest.java:35)
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:166)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:171)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	... 1 more

The test works perfectly with RobolectricTestRunner. Instrumentation config is incorrectly loaded.

Tests seems not to run in isolation

Copied from mscharhag/oleaster#16
The default JUnit runner isolate tests in a way that every test gets executed with a new test-case instance. This ensures a fresh fixture instance for each test, even if the developer uses an implicit setup shortcut.

It seems to me that Oleaster tests work always with the same fixture in such a case. This is because the test-case instance is reused for all test runs (see snippet below for a better understanding of the use-case).

This behavior might lead to problems which are difficult to understand. Although I am not a particular friend of this setup practice, I doubt that people will follow a do-not-use-this-kind-of-implicit-setup convention. Maybe it would be better to ensure this kind of isolation as JUnit does by default.

@RunWith( OleasterRunner.class )
public class OleasterTest {

  Object fixture = new Object();

  {  
    it( "first", () -> {
      System.out.println( "first: " + fixture.hashCode() );
    } );

    it( "second", () -> {
      System.out.println( "second: " + fixture.hashCode() );
    } );
  }
}

Method level config support

In Robolectric tests we can write:

@Config(sdk=21)
@Test
public void test() {
 ...
}

Since oleaster is not written on top of java.lang.reflect.Method, we can't associate annotations with lambda.

API - V21+ Not working due to missing styles

Trace:

com.example.harshitbangar.testapp.MainActivityTest
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:169)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.RuntimeException: An exception occurred while running invokable: You need to use a Theme.AppCompat theme (or descendant) with this activity.
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:168)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	... 21 more
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
	at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
	at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
	at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
	at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
	at com.example.harshitbangar.testapp.MainActivity.onCreate(MainActivity.java:13)
	at android.app.Activity.performCreate(Activity.java:5933)
	at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
	at org.robolectric.android.controller.ActivityController$1.run(ActivityController.java:73)
	at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:366)
	at org.robolectric.shadows.CoreShadowsAdapter$1.runPaused(CoreShadowsAdapter.java:27)
	at org.robolectric.android.controller.ActivityController.create(ActivityController.java:70)
	at org.robolectric.android.controller.ActivityController.create(ActivityController.java:80)
	at com.example.harshitbangar.testapp.MainActivityTest.lambda$null$0(MainActivityTest.java:35)
	at com.mscharhag.oleaster.runner.OleasterRunner.lambda$runInvokables$1(OleasterRunner.java:166)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at com.mscharhag.oleaster.runner.OleasterRunner.runInvokables(OleasterRunner.java:164)
	at com.mscharhag.oleaster.runner.OleasterRunner.runBeforeEachCallbacks(OleasterRunner.java:121)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:287)
	at com.mscharhag.oleaster.runner.OleasterRobolectricRunner.runChild(OleasterRobolectricRunner.java:57)
	at org.robolectric.internal.RoboOleaster.runChild(RoboOleaster.java:169)
	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	... 1 more

Process finished with exit code 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.