pull/1/head
Aniket-Engg 5 years ago
parent 23c65d077d
commit 1fd2882fbf
  1. 95
      docs/assert_library.md
  2. 1
      docs/index.rst
  3. 49
      docs/unittesting.md

@ -0,0 +1,95 @@
Remix Assert Library
====================
* [Assert.ok(value[, message])](#assert-ok-value-message)
* [Assert.equal(actual, expected[, message])](#assert-equal-actual-expected-message)
* [Assert.notEqual(actual, expected[, message])](#assert-notequal-actual-expected-message)
* [Assert.greaterThan(value1, value2[, message])](#assert-greaterthan-value1-value2-message)
* [Assert.lesserThan(value1, value2[, message])](#assert-lesserthan-value1-value2-message)
## Assert
### Assert.ok(value[, message])
* `value`: \<bool\>
* `message`: \<string\>
Tests if value is truthy. `message` is returned in case of failure.
Examples:
```
Assert.ok(true);
// OK
Assert.ok(false, "it\'s false");
// error: it's false
```
### Assert.equal(actual, expected[, message])
* `actual`: \<uint | int | bool | address | bytes32 | string\>
* `expected`: \<uint | int | bool | address | bytes32 | string\>
* `message`: \<string\>
Tests if `actual` & `expected` values are same. `message` is returned in case of failure.
Examples:
```
Assert.equal(string("a"), "a");
// OK
Assert.equal(uint(100), 100);
// OK
foo.set(200)
Assert.equal(foo.get(), 200);
// OK
Assert.equal(foo.get(), 100, "value should be 200");
// error: value should be 200
```
### Assert.notEqual(actual, expected[, message])
* `actual`: \<uint | int | bool | address | bytes32 | string\>
* `expected`: \<uint | int | bool | address | bytes32 | string\>
* `message`: \<string\>
Tests if `actual` & `expected` values are not same. `message` is returned in case of failure.
Examples:
```
Assert.notEqual(string("a"), "b");
// OK
foo.set(200)
Assert.notEqual(foo.get(), 200, "value should not be 200");
// error: value should not be 200
```
### Assert.greaterThan(value1, value2[, message])
* `value1`: \<uint | int\>
* `value2`: \<uint | int\>
* `message`: \<string\>
Tests if `value1` is greater than `value2`. `message` is returned in case of failure.
Examples:
```
Assert.greaterThan(uint(2), uint(1));
// OK
Assert.greaterThan(uint(-2), uint(1));
// OK
Assert.greaterThan(int(2), int(1));
// OK
Assert.greaterThan(int(-2), int(-1), "-2 is not greater than -1");
// error: -2 is not greater than -1
```
### Assert.lesserThan(value1, value2[, message])
* `value1`: \<uint | int\>
* `value2`: \<uint | int\>
* `message`: \<string\>
Tests if `value1` is lesser than `value2`. `message` is returned in case of failure.
Examples:
```
Assert.lesserThan(int(-2), int(-1));
// OK
Assert.lesserThan(int(2), int(1), "2 is not lesser than 1");
// error: 2 is not greater than 1
```

@ -65,6 +65,7 @@ Useful links:
remix_commands
remixd
unittesting
assert_library
.. toctree::
:maxdepth: 2

@ -3,45 +3,42 @@ Unit Testing
Click the
![double check](images/a-user-testing-icon.png)
icon to get to the "Solidity Unit Testing" plugin. If you don't see this icon, go to the plugin manager (by click the ![plug](images/a-plug.png) icon) and load up the unit testing plugin.
icon to get to the "Solidity Unit Testing" plugin.
If you haven't used this plugin before and not seeing `double check` icon, you have to activate it from Remix plugin manager.
Go to the plugin manager (by click the ![plug](images/a-plug.png) icon) and load up the unit testing plugin.
![](images/a-unit-testing-from-pm.png)
Now `double check` icon will appear on the left side icon bar. Clicking on icon will show UI related to unit testing.
![](images/a-unit-testing-feature.png)
Generating Test File
Generate Test File
------------------
Click the button "Generate test file" to create a new solidity file in the current folder.
This create a new solidity file suffixed with `_test`.
This file contains the minimum you need for running unit testing.
Click the button `Generate test file` to create a new solidity file in the current folder suffixed with `_test`. This file contains the minimum you need for running unit testing.
Write Tests
-----------
Write tests to check the functionality of your contract. Remix injects a built-in `assert` library which can be used for testing. Visit the library documentation [here](./assert_library).
Apart from this, Remix allows usage of some special functions to make testing more structural. They are:
Running Tests
* `beforeEach()` - Runs before each test
* `beforeAll()` - Runs before all tests
* `afterEach()` - Runs after each test
* `afterAll()` - Runs after all tests
To get started, see [this](https://github.com/ethereum/remix/blob/master/remix-tests/tests/examples_4/SafeMath_test.sol) for sample implementation.
Run Tests
------------------
Click the button "Run tests" to executes all tests whose box has been checked below (by default all). The execution is run in a separate environment and the result is displayed below.
![](images/a-unit-testing-run-result.png)
Here is a list of functions and their supported types that you can use to write your testcases:
```eval_rst
+ -----------------------+--------------------------------------------------------+
| Available functions | Supported types |
+========================+========================================================+
| `Assert.ok()` | `bool` |
+------------------------+--------------------------------------------------------+
| `Assert.equal()` | `uint`, `int`, `bool`, `address`, `bytes32`, `string` |
+------------------------+--------------------------------------------------------+
| `Assert.notEqual()` | `uint`, `int`, `bool`, `address`, `bytes32`, `string` |
+------------------------+--------------------------------------------------------+
| `Assert.greaterThan()` | `uint`, `int` |
+------------------------+--------------------------------------------------------+
| `Assert.lesserThan()` | `uint`, `int` |
+------------------------+--------------------------------------------------------+
```
Click [here](https://github.com/ethereum/remix/blob/master/remix-tests/tests/examples_4/SafeMath_test.sol) for a test file example
Continuous integration
----------------------

Loading…
Cancel
Save