Giter Site home page Giter Site logo

square / assertj-android Goto Github PK

View Code? Open in Web Editor NEW
1.6K 73.0 167.0 3.15 MB

A set of AssertJ helpers geared toward testing Android.

Home Page: https://square.github.io/assertj-android/

License: Apache License 2.0

Shell 0.26% Java 98.11% Python 0.46% CSS 0.14% HTML 1.02%

assertj-android's Introduction

AssertJ Android

A set of AssertJ assertions geared toward testing Android.

Deprecated

The support libraries and play services are developing at a rate which this library cannot sustain. Additionally, we no longer think AssertJ's model for supporting alternate assertions is a good practice.

We recommend using Truth which has vastly superior extensibility model which, when coupled with things like Kotlin's apply method create a really nice assertion experience.


Writing tests is not the most glamorous part of developing an Android application but it is an invaluable one. Using libraries like JUnit and AssertJ provide a great starting point for writing tests.

This library is an extension of AssertJ which aims to make it even easier to test Android.

Examples

  • AssertJ Android:

    assertThat(view).isGone();
  • Regular JUnit:

    assertEquals(View.GONE, view.getVisibility());
  • Regular AssertJ:

    assertThat(view.getVisibility()).isEqualTo(View.GONE);

When failing, the AssertJ Android assertion produces an output which allows you to immediately recognize the problem: Expected visibility <gone> but was <invisible>.

Compare that to the output of regular AssertJ Expected:<[8]> but was:<[4]> and regular JUnit Expected: <8> but was: <4> and you should immediately see the advantage.

Because AssertJ Android offers assertions directly on objects rather than properties they can be chained together.

  • AssertJ Android:

    assertThat(layout).isVisible()
        .isVertical()
        .hasChildCount(4)
        .hasShowDividers(SHOW_DIVIDERS_MIDDLE);
  • Regular JUnit:

    assertEquals(View.VISIBLE, layout.getVisibility());
    assertEquals(VERTICAL, layout.getOrientation());
    assertEquals(4, layout.getChildCount());
    assertEquals(SHOW_DIVIDERS_MIDDLE, layout.getShowDividers());
  • Regular AssertJ:

    assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);
    assertThat(layout.getOrientation()).isEqualTo(VERTICAL);
    assertThat(layout.getChildCount()).isEqualTo(4);
    assertThat(layout.getShowDividers()).isEqualTo(SHOW_DIVIDERS_MIDDLE);

Assertions exist for nearly every object that you would ever want to test, from LinearLayout to ActionBar to Fragment to MenuItem. Everything in the support library is included too.

To get started writing tests add the following import:

import static org.assertj.android.api.Assertions.assertThat;

Add-On Modules

Modules are also provided for the add-on Android libraries. Add the dependency (listed below) and use the following imports:

  • support-v4: import static org.assertj.android.support.v4.api.Assertions.assertThat;
  • play-services: import static org.assertj.android.playservices.api.Assertions.assertThat;
  • appcompat-v7: import static org.assertj.android.appcompat.v7.api.Assertions.assertThat;
  • mediarouter-v7: import static org.assertj.android.mediarouter.v7.api.Assertions.assertThat;
  • gridlayout-v7: import static org.assertj.android.gridlayout.v7.api.Assertions.assertThat;
  • cardview-v7: import static org.assertj.android.cardview.v7.api.Assertions.assertThat;
  • recyclerview-v7: import static org.assertj.android.recyclerview.v7.api.Assertions.assertThat;
  • palette-v7: import static org.assertj.android.palette.v7.api.Assertions.assertThat;

Extending

The provided assertions have also been designed to be extended for any custom controls you have developed.

public class CustomLayout extends LinearLayout {
  public int getBehavior() {
    /* ... */
  }
}

Use the following pattern to set up your assertions.

public class CustomLayoutAssert extends AbstractLinearLayoutAssert<CustomLayoutAssert, CustomLayout> {
  public static CustomLayoutAssert assertThat(CustomLayout actual) {
    return new CustomLayoutAssert(actual);
  }

  public CustomLayoutAssert(CustomLayout actual) {
    super(actual, CustomLayoutAssert.class);
  }

  public CustomLayoutAssert hasSomeBehavior() {
    isNotNull();
    assertThat(actual.getBehavior())
        .overridingErrorMessage("Expected some behavior but was doing other behavior.")
        .isEqualTo(42)
    return this;
  }
}

Now static import CustomLayoutAssert.assertThat in your test classes.

For more information about writing custom assertions see the official documentation.

Download

Android module:

androidTestCompile 'com.squareup.assertj:assertj-android:1.2.0'

support-v4 module:

androidTestCompile 'com.squareup.assertj:assertj-android-support-v4:1.2.0'

Google Play Services module:

androidTestCompile 'com.squareup.assertj:assertj-android-play-services:1.2.0'

appcompat-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-appcompat-v7:1.2.0'

Design library module:

androidTestCompile 'com.squareup.assertj:assertj-android-design:1.2.0'

mediarouter-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-mediarouter-v7:1.2.0'

gridlayout-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-gridlayout-v7:1.2.0'

cardview-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-cardview-v7:1.2.0'

recyclerview-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-recyclerview-v7:1.2.0'

palette-v7 module:

androidTestCompile 'com.squareup.assertj:assertj-android-palette-v7:1.2.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2013 Square, 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.

assertj-android's People

Contributors

aahlenst avatar alexruiz avatar arturdryomov avatar bananeweizen avatar chris-horner avatar dnkoutso avatar donnfelker avatar edenman avatar erd avatar f2prateek avatar holmes avatar jakewharton avatar jrodbx avatar jsoref avatar jtietema avatar krzysiekbielicki avatar lucasr avatar makovkastar avatar mariusvolkhart avatar matthewmichihara avatar michaelevans avatar neodaoist avatar pidelport avatar plastiv avatar rcdickerson avatar roman-mazur avatar sberan avatar sethew avatar thorikawa avatar xian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assertj-android's Issues

gradle build fails with android lint errors: "NewApi: Calling new methods on older versions" x 500

I'm assuming everyone else is building this with gradle, so I'm guessing something's wrong with my local setup? In that case, any pointers on what might be wrong? On the other hand, fest-assert is just for tests, so maybe abortOnError should be turned off?

./gradlew build yields:

:androidJavadocs UP-TO-DATE
    ... <snipped> ...
:assemble UP-TO-DATE
:checkstyleDebug UP-TO-DATE
:checkstyleRelease UP-TO-DATE
:lint
Ran lint on variant release: 558 issues found
Ran lint on variant debug: 558 issues found
Wrote HTML report to file:fest-android/build/lint-results.html
Wrote XML report to fest-android/build/lint-results.xml
:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':lint'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

To see the lint errors: open build/lint-results.html

There are 500 errors similar to this one:

../src/main/java/org/fest/assertions/api/android/widget/AbstractAbsListViewAssert.java:15: 
Call requires API level 11 (current min is 7): android.widget.AbsListView#getCheckedItemCount

Question: mix core and android assertions

Hi guys,

Are there good way to mix core and android assertions? Currently I static import android assertions class and I have to specify with package assertions from core. Is there easier way?

In general, by design, would it be acceptable to have assertions in the same package as core. Or maybe it is better to write proxy classes that will call core assertions?

Add and use BitMaskStringBuilder

public class BitMaskStringBuilder
  private final int flags;
  private final Set<String> parts = new LinkedHashSet<String>();

  public BitMaskStringBuilder(int flags) {
    this.flags = flags;
  }

  public BitMaskStringBuilder flag(int flag, String flagName) {
    if ((flags & flag) != 0) {
      parts.add(flagName);
    }
  }

  public String get() {
    StringBuilder result = new StringBuilder();
    for (String part : parts) {
      if (result.length() > 0) {
        result.add(", ");
      }
      result.add(part);
    }
    return result.toString();
  }
}

Google Play Services 5.0 - org.fest.reflect.exception.ReflectionError

I'm getting the following stacktrace when running my Robolectric tests. Not sure if this is something that should be addressed in Fest or Robolectric (assuming I'm not doing something wrong).

The problem line looks to be:

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
org.fest.reflect.exception.ReflectionError: Unable to invoke method 'performCreate' with arguments [null]
    at org.fest.reflect.method.Invoker.cannotInvokeMethod(Invoker.java:124)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:116)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:113)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265)
    at org.robolectric.util.ActivityController.create(ActivityController.java:110)
    at org.robolectric.util.ActivityController.create(ActivityController.java:120)
    at com.company.myapp.activities.MainActivityTest.setupActivity(MainActivityTest.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.VerifyError: Expecting a stackmap frame at branch target 47
Exception Details:
  Location:
    com/google/android/gms/common/GooglePlayServicesUtil.<init>()V @19: ifnull
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2ab7 036a 2ab6 0370 1303 7203 1202 b803
    0000010: 784c 2bc6 001c 2b2a 2ab6 037c 03bd 0004
    0000020: b903 8204 0057 a700 144d 2cb8 0386 bf2a
    0000030: b703 6db1 4d2c b803 86bf b1            
  Exception Handler Table:
    bci [22, 38] => handler: 41
    bci [47, 51] => handler: 52

    at com.company.myapp.activities.LocationAwareActivity.servicesConnected(LocationAwareActivity.java:69)
    at com.company.myapp.activities.LocationAwareActivity.onCreate(LocationAwareActivity.java:32)
    at com.company.myapp.activities.MainActivity.onCreate(MainActivity.java:70)
    at android.app.Activity.performCreate(Activity.java:5133)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:113)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265)
    at org.robolectric.util.ActivityController.create(ActivityController.java:110)
    at org.robolectric.util.ActivityController.create(ActivityController.java:120)
    at com.company.myapp.activities.MainActivityTest.setupActivity(MainActivityTest.java:21)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    ... 7 more

Switch to Building with Gradle

TODO

  • Gradle build scripts.
  • Attach a .jar to the artifacts when deploying for non-Gradle users.
  • Kill the Maven build system.
  • Add assertions for API 17+ things!

Error since the new com.android.tools.build:gradle

Hello,

I'm using fest-android for my unit testing and I first would like to thank you for your great job.
Yet, I'm encountering an error since I have updated Android's gradle tool to version 0.12.
Here is the error message : Module version com.squareup:fest-android:1.0.8 depends on libraries but is not a library itself.

That would be great if you could fix this issue.

Thank you very much.

Best regards

java.lang.NoClassDefFoundError: org.fest.assertions.api.android.view.ViewAssert

Hi,

i am trying to use the assertThat function for a ImageView/view. This is my my first test case with fest library. I am getting runtime exception while running the test cases. I am using Android 4.2 version.Here is exception trace

java.lang.NoClassDefFoundError: org.fest.assertions.api.android.view.ViewAssert
at org.fest.assertions.api.ANDROID.assertThat(ANDROID.java:615)
at com.android.mobile.test.matches.NewUserDefaultMatchesTest.testTapOnEditButtonEnableEditActions(NewUserDefaultMatchesTest.java:134)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)

I have added library to Build path and put in libs directory of the test project. Please let me know where am doing wrong.

Regards,
Gogineni

honor .as() method on asserts

Update various asserts to honor descriptions passed to "as".

E.g.

assertThat(fooView).as("Foo").isGone()

would print:

Expected Foo to be gone but was visible

For example isGone would contain would be roughly ( based on your current code ):

assertThat(actualVisibility) 
        .overridingErrorMessage("Expected " +
        getWritableAssertionInfo().getDescriptionText() 
             + " to be gone but was %s",
            visibilityToString(actualVisibility)) 
        .isEqualTo(GONE);

Reference:

https://github.com/alexruiz/fest-assert-2.x/blob/fest-assert-core-2.0M10/src/main/java/org/fest/assertions/api/AbstractAssert.java

https://github.com/alexruiz/fest-assert-2.x/blob/fest-assert-core-2.0M10/src/main/java/org/fest/assertions/core/WritableAssertionInfo.java

java.lang.VerifyError: org.fest.assertions.internal.Objects when testing ListView visibility

When I test the visibility of a ListView with assertThat(mLst).isVisible();
I get a test failure with the following trace!
java.lang.VerifyError: org.fest.assertions.internal.Objects
at org.fest.assertions.api.AbstractAssert.(AbstractAssert.java:43)
at org.fest.assertions.api.android.view.AbstractViewAssert.(AbstractViewAssert.java:27)
at org.fest.assertions.api.android.view.AbstractViewGroupAssert.(AbstractViewGroupAssert.java:18)
at org.fest.assertions.api.android.widget.AbstractAdapterViewAssert.(AbstractAdapterViewAssert.java:13)
at org.fest.assertions.api.android.widget.AbstractAbsListViewAssert.(AbstractAbsListViewAssert.java:10)
at org.fest.assertions.api.android.widget.AbstractListViewAssert.(AbstractListViewAssert.java:12)
at org.fest.assertions.api.android.widget.ListViewAssert.(ListViewAssert.java:13)
at org.fest.assertions.api.ANDROID.assertThat(ANDROID.java:920)
at com.fontself.sms.test.MessageActivityTest.testEnterText(MessageActivityTest.java:84)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

(v1.0.0) release ETA

Do you guys have an ETA of a first release of assertj-android into maven-central? (even if it's just a beta release)

I'd like to start using the lib already...

Invalid version of support-v4 in POM

The POM pushed to Maven central contains this dependency:

<dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-v4</artifactId>
      <version>19.1.+</version>
      <scope>compile</scope>
</dependency>

The version format 19.1.+ is illegal in Maven (i know it comes from Gradle). Please consider modifying the version number.

Browse available assertions?

It's possible I'm just being dense, but I was looking for a browseable list of assertions provided by fest-android. Maybe browseable by type.

Or is the intended use here to pass an object to assertThat and then poke around in autocomplete and see what pops up?

Compilation Error: class file for android.app.TaskStackBuilder not found

Hey guys,

First time trying to use this lib. Dropped the dependency in my pom, wrote a quick test just to inflate a View into an Activity, and assert that it isn't null. When I try to compile, I get the error:

class file for android.app.TaskStackBuilder not found

I've only tried a single assertion:

assertThat(view).isNotNull();

the error points back directly to this line.

hasText() in AbstractTextViewAssert fails for Spannables

I'm doing

textView.setText(Html.fromHtml("<b>Some bold text</b> with other text"));

in code, and the assertion

assertThat(textView).hasText("<b>Some bold text</b> with other text");

fails with the message:

Expected text <<b>Some bold text</b> with other text> but was <<b>Some bold text</b> with other text>

I expect the assertion to pass because the text is the same.

Website is not deployed

Because I'm sure someone else will file this issue...

Also needs updated with the new multi-module scheme that the readme has.

Add View tree traversal JQuery inspired assertions

Was just writing a test and really wanted to write something like:

assertThat(viewGroup).has(textView).withText("fest!");

or perhaps

assertThat(viewGroup).has(TextView.class).withText("fest!");

is better design.

Stable version is so old

It'd be really great if you could create a new release and push it to maven repos. The current one is 8 months old (I assume that from the last modification of the changelog) and it's missing important fixes, e.g.: a5b1529

Can't compile version 1.0.8

I've updated Gradle build tools to version 0.10 and fest version from 1.0.7 to 1.0.8. When I run my robolectric unit tests I receive this error from fest classes:

warning: org/fest/assertions/api/ANDROID.class(org/fest/assertions/api:ANDROID.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.

And my unit tests don't run anymore. But if I downgrade to fest v1.0.7 everything just go fine, so that's why I think the error could be in this new version. Also I'm using this plugin to run the robolectric tests: 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'

URL in the readme is dead

From the README:
This library is an extension of FEST which aims to make it even easier to test Android.

http://fest.easytesting.org/

leads to an empty blog

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Can't build with gradle: No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

Sorry to post here, but I couldn't find a mailing list anywhere.

I'm unable to build the project locally (see error message below from gradle). Any ideas on how to fix this?

$ ./gradlew 

FAILURE: Build failed with an exception.

* Where:
Script 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' line: 48

* What went wrong:
A problem occurred configuring root project 'fest-android'.
> No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Add compatibility with older SDKs

We set IntelliJ to SDK level 2.3.3 so that we don't get autocompletes for more modern APIs that aren't going to be available on older phones, but when we do that we get mysterious looking errors for matchers that handle things like android.animation.Animator which didn't exist in 2.3.3. We had the same problem when we didn't link against the support library. When we ran into this on Robolectric we solved it by having multiple versions of classes that were supersets of each other, so there could be ANDROID10.assertThat and ANDROID16.assertThat. It was a little ugly looking to implement, but it's been convenient to use. Maybe Fest-Android could do something similar.

Alternatively, there could be a "legacy" branch or fork of fest-android that catered to the older API levels.

Phil & Dave

Missing maven/gradle dependency?

I tried to use this lib via gradle, but when I start the tests it complained that it wasn't able to find the support-v4 library. Since I don't use that in my app (yet) I had to manually add it via instrumentTestCompile. Would it make sense to include the support library as a dependency to fest-android?

Release jar packaged artifact

I looked at the snapshot release and i see it only comes with AAR packaging. Can we get an artifact with simple jar packaging? This way this library could be easily used in eclipse, where there is no way to use AARs. Actually i see no reason to package this library as an AAR, since this contains only classes, no resources, also its nature fits a jar much more.

AbstractTextViewAssert.hasText() leads to java.util.UnknownFormatConversionException if text contains "%"

Assuming that a text view contains the '%' character, calling

assertThat(textView).hasText("any text")

will throw java.util.UnknownFormatConversionException if the assertion fails (expected text is not actual text).

This is due to AssertionError.failureIfErrorMessageIsOverriden() calling MessageFormatter.instance().format().

The solution would be to escape '%' characters in the description to be formatted.

The type org.fest.assertions.api.AbstractAssert cannot be resolved

Trying to build a sample test app to use Fest in Eclipse.

It fails to build with this error
"The type org.fest.assertions.api.AbstractAssert cannot be resolved. It is indirectly referenced from required .class files"

It looks like the AbstractAssert class is missing.

I tried to build the test sample in the Spoon Sample and it also failed with the same issue.

Update Generation Script To Understand Generics

public class LruCacheAssert<K, V> extends AbstractAssert<LruCacheAssert<K, V>, LruCache<K, V>> {

should generate:

public static <K, V> LruCacheAssert<K, V> assertThat(LruCache<K, V> actual) {
  return new LruCacheAssert<K, V>(actual);
}

Unable to import static method assertThat

I replaced the line in my build.gradle file that declared using Fest-Android with one for AssertJ-Android:

-    androidTestCompile('com.squareup:fest-android:1.0.+') {
+    androidTestCompile('com.squareup.assertj:assertj-android:1.0.0') {

The issue is that after replacing all static imports of import static org.fest.assertions.api.ANDROID.assertThat; with import static org.assertj.android.api.Assertions.assertThat;, the static import isn't found therefore my Robolectric tests fail to compile. If I change the Gradle line to use compile instead of androidTestCompile, the tests work correctly but obviously that's not optimal nor what the documentation describes.

The error returned by javac is the following:

File.java:โˆž error: package org.assertj.android.api does not exist
import static org.assertj.android.api.Assertions.assertThat;
                                     ^

AssertJ module

Have you thought about supporting AssertJ instead of/in addition to fest-assert-2.x? fest-assert-2.x is dormant and if it comes to life again chances are it is going to be less useful (there are plans to remove a lot of assertions, see alexruiz/fest-assert-2.x#159 and https://github.com/joel-costigliola/assertj-core#why-have-we-forked-fest-assert). I'd be willing to provide a patch, but it would be a breaking change (packages have to be renamed) and eventually involve renaming the project to assertj-android.

TextViewAssert's isEmpty() doesn't work with EditText

I'll be happy to submit a well tested patch once you confirm this is a bug.

It seems it uses hasText("") when it should use hasTextString("").
Can anybody reproduce?

assertThat(new EditText(anyActivity)).isEmpty(); // always fails

Use FEST Assertions 2.0M10

2.0M10 fixes a small incompatibility with Android as reported here.

It might be better for fest-android to depend on this version.

Missing AbstractTextViewAssert.hasTextColor(int) method

Beside hasText() and hasTextSize() the class AbstractTextViewAssert is missing the test method hasTextColor(int). In my test case there's need to check the correct color.

Edit: Android returns a TextView's text color with getCurrentTextColor(). Accordingly AbstractTextViewAssert provided hasCurrentTextColor(int). So this issue is closed.

hasText() sometimes returns false negatives

Sometimes fails with messages like: "Expected text but was "
This happens because the text is actually a CharSequence that doesn't compare nicely with String. In my case it was a SpannableStringBuilder. Maybe a nice way to fix this would be to check whether the 'text' parameter is actually a String and call toString() on actualText before doing the comparison:

public S hasText(CharSequence text) {
isNotNull();
CharSequence actualText = actual.getText();
if (text instanceOf String) actualText = actualText.toString();
assertThat(actualText) //
.overridingErrorMessage("Expected text <%s> but was <%s>.", text, actualText) //
.isEqualTo(text);
return myself;
}

That way in the 1% case where someone really wants to ensure that a text field has some exact configuration of a SpannableStringBuilder as it's text they can still build one up and pass it in, while the rest of the time we'll get the String comparison we'd intuitively expect.

assertThat Compilation Error with Text View

I'm currently trying to integrate FEST with robolectric on my project. I succeeded in enabling robolectric but when I try to integrate FEST with one of my text views. I get the following:

java: cannot access android.animation.Animator class file for android.animation.Animator not found

The unit test looks as follows:

    @Test
    public void textViewVisible() {
        TextView textView = (TextView) mActivity.findViewById(R.id.my_id);
        assertThat(textView).isVisible()
                .hasCurrentTextColor(Color.parseColor("#34a7ff"))
                .containsText("1");
    }

I'm using Intellij and my module sdk is Android 2.3.3 Google Apis

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.