forked from assertj/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams.json
More file actions
1 lines (1 loc) · 9.61 KB
/
Copy pathparams.json
File metadata and controls
1 lines (1 loc) · 9.61 KB
1
{"name":"Assertj-core","tagline":"AssertJ is a library of assertions similar to fest-assert but providing a richer set of assertions.","body":"# AssertJ - a rich assertions library for java \r\n\r\nAssertJ provides a rich and intuitive set of strongly typed assertions to use for unit testing (either with JUnit or TestNG). \r\n\r\n* [AssertJ's goals](#goals)\r\n* [Latest News](#news)\r\n* [Quick start](#quickstart)\r\n* [Assertions for your own custom types](#custom types-assertions)\r\n* [Replacing JUnit assertions by AssertJ Assertions](#junit-to-assertj-assertions)\r\n* [Why having forked Fest Assert ?](#fest-assertj)\r\n* [Migrating from Fest assertions](#migrating-from-fest)\r\n* [Documentation & Mailing list](#doc)\r\n* [Contributing](#contributing)\r\n\r\nYou can ask questions and make suggestions on [AssertJ google group](https://groups.google.com/forum/?fromgroups=#!forum/assertj). \r\nTo directly jump to a more complete documentation please go to **[AssertJ wiki](https://github.com/joel-costigliola/AssertJ-core/wiki)**.\r\n\r\n## <a name=\"goals\"/>AssertJ's goals\r\n\r\nAssertJ's ambition is to provide a rich and intuitive set of strongly typed assertions to use for unit testing. \r\nThe idea is that, when writing unit tests, we should have at our disposal assertions specific to the type of the objects we are checking : you are checking a String ? use String specific assertions ! \r\n\r\nAssertJ is composed of several modules :\r\n* A core module (this one) to provide assertions for JDK types (String, Collections, File, Map ...). \r\n* A **[Guava module](https://github.com/joel-costigliola/assertj-guava#readme)** to provide assertions for Guava types (Multimap,Optional, ...).\r\n* A **[Joda Time module](https://github.com/joel-costigliola/assertj-joda-time#readme)** to provide assertions for Joda Time types (DateTime, LocalDateTime).\r\n\r\nAssertion missing ? Please [fill a ticket](https://github.com/joel-costigliola/assertj-core/issues) ! \r\n\r\nAssertJ's assertions are super easy to write: just type **```assertThat```** followed the actual value and a dot, and any Java \r\nIDE will show you all the assertions available for the type of the object to verify. No more confusion about the \r\norder of the \"expected\" and \"actual\" values. Our assertions are very readable as well: they read very close to plain \r\nEnglish, making it easier for non-technical people to read test code. \r\nA lot of efforts have to provide intuitive error messages showing as clearly as possible what the problem is.\r\n\r\nNote that AssertJ requires at least Java 6.\r\n\r\nFor more details check **[AssertJ wiki](https://github.com/joel-costigliola/assertj-core/wiki/)**.\r\n\r\n## <a name=\"news\"/>Latest News\r\n\r\n**2013-03-28 : AssertJ quickie presentation at Devoxx France !**\r\n\r\n**2013-03-26 - AssertJ train releases :** \r\n* **assertj-core 1.0.0**\r\n* **assertj-guava 1.0.0**\r\n* **assertj-joda-time 1.0.0**\r\n* **assertj-assertions-generator 1.0.0**\r\n* **assertj-assertions-generator-maven-plugin 1.0.0**\r\n\r\nSee [**what's new**](https://github.com/joel-costigliola/assertj-core/wiki/New-and-noteworthy) in assertj-core compared to Fest. \r\n\r\n\r\n## <a name=\"quickstart\"/>Quickstart\r\n\r\nIt is easy to start using AssertJ, it should take you less than a minute !\r\n\r\n#### 1 - Get AssertJ core \r\n\r\nAssertJ core is available in Maven central repository.\r\n\r\n```xml\r\n<dependency>\r\n <groupId>org.assertj</groupId>\r\n <artifactId>assertj-core</artifactId>\r\n <version>1.0.0</version>\r\n <scope>test</scope>\r\n</dependency>\r\n```\r\n\r\n### 2 - Add Assertions.* static import\r\n\r\n```java\r\nimport static org.assertj.core.api.Assertions.*;\r\n```\r\nor the complete list\r\n```java\r\nimport static org.assertj.core.api.Assertions.assertThat; // main one\r\nimport static org.assertj.core.api.Assertions.atIndex; // for List assertions\r\nimport static org.assertj.core.api.Assertions.entry; // for Map assertions\r\nimport static org.assertj.core.api.Assertions.extractProperty; // for Iterable/Array assertions\r\nimport static org.assertj.core.api.Assertions.fail; // use when making exception tests\r\nimport static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; // idem\r\nimport static org.assertj.core.api.Assertions.filter; // for Iterable/Array assertions\r\nimport static org.assertj.core.api.Assertions.offset; // for floating number assertions\r\nimport static org.assertj.core.api.Assertions.anyOf; // use with Condition\r\nimport static org.assertj.core.api.Assertions.contentOf; // use with File assertions\r\n```\r\n\r\nYou can even configure your IDE, so that when you type `asse` and trigger code completion, it will suggest `assertThat`.\r\n\r\n### 3 - Type **assertThat** followed by the actual value and a dot ... \r\n\r\n... and any Java IDE code completion will show you all the assertions available.\r\n\r\nThat's all !\r\n\r\n\r\n\r\n### Some assertions examples\r\n\r\n```java\r\nimport static org.assertj.core.api.Assertions.*;\r\n\r\n// some of the assertions available for all types\r\nassertThat(yoda).isInstanceOf(Jedi.class);\r\nassertThat(frodo.getName()).isEqualTo(\"Frodo\");\r\nassertThat(frodo).isNotEqualTo(sauron);\r\nassertThat(frodo).isIn(fellowshipOfTheRing);\r\nassertThat(sauron).isNotIn(fellowshipOfTheRing);\r\n\r\n// String specific assertions\r\nassertThat(frodo.getName()).startsWith(\"Fro\").endsWith(\"do\")\r\n .isEqualToIgnoringCase(\"frodo\");\r\n\r\n// collection specific assertions\r\nassertThat(fellowshipOfTheRing).hasSize(9)\r\n .contains(frodo, sam)\r\n .doesNotContain(sauron);\r\n// Exception/Throwable specific assertions\r\ntry {\r\n fellowshipOfTheRing.get(9); \r\n // argggl ! fellowshipOfTheRing size is 9 and get(9) asks for the 10th element !\r\n} catch (Exception e) {\r\n assertThat(e).isInstanceOf(IndexOutOfBoundsException.class)\r\n .hasMessage(\"Index: 9, Size: 9\")\r\n .hasNoCause();\r\n}\r\n\r\n// Map specific assertions, ringBearers is a Map of Ring -> TolkienCharacter\r\nassertThat(ringBearers).hasSize(4)\r\n .includes(entry(Ring.oneRing, frodo), entry(Ring.nenya, galadriel))\r\n .excludes(entry(Ring.oneRing, aragorn));\r\n```\r\n\r\n## <a name=\"custom types-assertions\"/>Assertions for your own custom types \r\n\r\nHaving assertions for common types like List is great but it would so nice to have some for your own types ! \r\n\r\nWell this is possible with AssertJ because it is easily extensible so it's simple to [write assertions for your custom types](https://github.com/joel-costigliola/assertj-core/wiki/Creating-specific-assertions). \r\nMoreover, to ease your work, we provide assertions generator that can take a bunch of custom types and create for you specific assertions, we provide : \r\n* a **[CLI assertions generator](https://github.com/joel-costigliola/assertj-assertions-generator#readme)** \r\n* A **[Maven plugin assertions generator](https://github.com/joel-costigliola/assertj-assertions-generator-maven-plugin#readme)** \r\n* An Eclipe plugin assertions generator (available soon)\r\n\r\n## <a name=\"junit-to-assertj-assertions\"/>Replacing JUnit assertions by AssertJ Assertions\r\n\r\nTo help you replace JUnit assertions by AssertJ ones, follow the steps described [**here**](https://github.com/joel-costigliola/assertj-core/wiki/Converting-JUnit-assertions-to-AssertJ-Assertions), they are based on regex search and replace.\r\n\r\n## <a name=\"fest-assertj\"/>Why having forked Fest Assert ?\r\n\r\nAssertJ is a fork of FEST Assert a great project I have contributed to during 3 years, so why having forked it ? \r\n\r\nWell there are two main reasons : \r\n* FEST 2.0 will only provide a limited set of assertions, far less than Fest 2.0M10 and even less than FEST 1.x. \r\n* FEST is not enough open to users demands and contributions.\r\n\r\nOn the contrary **AssertJ goal is to provide a rich set of assertions** and any resonable requests to enrich AssertJ assertions is welcome as we know it will be useful to someone. Said otherwise, AssertJ is **community driven**, we listen to our users because AssertJ is built for them. \r\n\r\nIf you feel that some assertion is missing, please [**fill a ticket**](https://github.com/joel-costigliola/assertj-core/issues) or even better make a contribution ! \r\n\r\n_Joel Costigliola (AssertJ creator)_\r\n\r\n## <a name=\"migrating-from-fest\"/>Migrating from Fest assertions\r\n\r\nAs AssertJ starts where Fest 2.0M10 has left, migrating from Fest to AssertJ Assertions is easy, you only have to change your static import, just replace :\r\n\r\n```java \r\nimport static org.fest.assertions.api.Assertions\r\n``` \r\n\r\nby :\r\n\r\n```java \r\nimport static org.assertj.core.api.Assertions\r\n```\r\n\r\nThis should be all, if not please fill a ticket so that I can update this section.\r\n\r\nIf you are using Fest Assert 1.x, please read this [migration guide](https://github.com/joel-costigliola/assertj-core/wiki/Migrating-from-FEST-Assert-1.4).\r\n\r\n## <a name=\"doc\"/>Documentation & Mailing list\r\n\r\nYou can ask questions and make suggestions on [**AssertJ google group**](https://groups.google.com/forum/?fromgroups=#!forum/assertj). \r\nTo directly jump to a more complete documentation please go to **[AssertJ wiki](https://github.com/joel-costigliola/AssertJ-core/wiki)**.\r\n\r\n## <a name=\"contributing\"/>Want to contribute ?\r\n\r\nYou are very welcome to contribute any missing useful assertions, please check the [contributor guidelines](CONTRIBUTING.md).\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}