Showing posts with label TDD. Show all posts
Showing posts with label TDD. Show all posts

Getting started with Android development with React Native without an IDE

Untitled

PC checklist:

  • install android SDK
  • install android build tools ( for building from the command line ) and set PATH variables
  • install nodejs 12(>= recommended)

ANDROID device checklist:

  • enable developer mode
  • enable usb debugging within developer mode
  • connect your android phone to laptop and tap allow on your phone

On PC:

Install React Native:

npm install react react-native yarn

Install React Native CLI

npm install react-natice-cli -g

Create new project:

react-native init myproject

Setting project package name:

npm install react-native-rename -g react-native-rename “myproject” -b com.mycompany.myapp

This is at the moment a workaround, because of issue: https://github.com/facebook/react-native/issues/12721. Future releases are suppossed to support --package

Clean / Build project:

react-native run-android –tasks clean

Build:

react-native run-android –tasks build

Installing app on connected android device and starting up the app:

react-native run-android –tasks installRelease

Project structure:

  • App.js
  • index.js
  • app.json
  • babel.config.js
  • android/…
  • ios/…
  • __tests__/App-test.js
  • package.json

Seeing logs:

Or:

adb logcat|grep React

Sample logs for putting:

in App.js:

App.js:

Output logs:

09-16 16:10:41.813 28599 28616 D ReactNative: Initializing React Xplat Bridge after initializeBridge
09-16 16:10:41.814 28599 28616 D ReactNative: CatalystInstanceImpl.runJSBundle()
09-16 16:10:41.840 28599 28621 D ReactNative: ReactInstanceManager.setupReactContext()
09-16 16:10:41.840 28599 28621 D ReactNative: CatalystInstanceImpl.initialize()
09-16 16:10:41.845 28599 28621 D ReactNative: ReactInstanceManager.attachRootViewToInstance()
09-16 16:10:42.166 28599 28620 I ReactNativeJS: #####Hi
09-16 16:10:42.206 28599 28620 I ReactNativeJS: Running application “MyTestProject” with appParams: {“rootTag”:1}. DEV === false, development-level warning are OFF, performance optimizations

Unit Testing:

React Native preconfigures Jest for unit testing. Running:

yarn test

should give:


yarn run v1.12.3
$ jest
 PASS  __tests__/App-test.js (10.046s)
  ✓ renders correctly (7236ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        11.149s
Ran all test suites.
Done in 12.92s. 

Lets put some unit tests in __tests__/App-test.js:

Next yarn test should give us:


yarn run v1.12.3
$ jest
 PASS  __tests__/App-test.js
  ✓ adds 4 + 5 to equal 9 (3ms)
  ✓ renders correctly (377ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        1.555s
Ran all test suites.
Done in 2.27s.

Debugging App Crashes / App sudden stop:

For facing REs start Metro JS bundler and run app on debug mode. Simply run react-native start on a new terminal window. Or running this in current terminal should start up a new window running Metro:

now run:

This should start app up in debug mode:

Now saving any changes on App.js should refresh android app istance window instantly running on device while designing UI. And any exception messages whould should right appear on app window.

Simplest way to run/test a php function in Laravel-4 ( Helloworld unit testing! )

Install phpunit:
1. Go to the root directory of your project (where the 'artisan' file is located).
2. Open 'composer.json. Include phpunit dependency in the JSON.
 Save and close the file. After adding the file content should look like:
  1. {
  2. "name": "laravel/laravel",
  3. "description": "The Laravel Framework.",
  4. "keywords": ["framework", "laravel"],
  5. "license": "MIT",
  6. "require": {
  7. "laravel/framework": "4.0.*",
  8. "geoip/geoip": "~1.14"
  9. },
  10. "require-dev": {
  11. "phpunit/phpunit": "3.7.*"
  12. },
  13. "autoload": {
  14. "classmap": [
  15. "app/commands",
  16. "app/controllers",
  17. "app/models",
  18. "app/database/migrations",
  19. "app/database/seeds",
  20. "app/tests/TestCase.php"
  21. ]
  22. },
  23. "scripts": {
  24. "post-install-cmd": [
  25. "php artisan optimize"
  26. ],
  27. "post-update-cmd": [
  28. "php artisan clear-compiled",
  29. "php artisan optimize"
  30. ],
  31. "post-create-project-cmd": [
  32. "php artisan key:generate"
  33. ]
  34. },
  35. "config": {
  36. "preferred-install": "dist"
  37. },
  38. "minimum-stability": "dev"
  39. }

3. Run the following command in that directory :
 
  1. composer update

 and wait for completion.

4. Now after that run the command "vendor\bin\phpunit" ("vendor/bin/phpunit" for linux)
 for running default tests
On Windows run:
  1. vendor\bin\phpunit
On Linux run:
  1. vendor/bin/phpunit
You will see something like this:


PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from YOUR_PROJECT_DIR\phpunit.xml

.

Time: 188 ms, Memory: 5.50Mb

←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K

7. Now go to the directory YOUR_PROJECT_DIR/app/tests/
8. Open the file 'ExampleTest.php'. It's content should look something like this:

  1. <?php
  2. class ExampleTest extends TestCase {
  3. /**
  4. * A basic functional test example.
  5. *
  6. * @return void
  7. */
  8. public function testBasicExample()
  9. {
  10. $crawler = $this->client->request('GET', '/');
  11. $this->assertTrue($this->client->getResponse()->isOk());
  12. }
  13. }
  14. 7. Now write your own test function and call it in testBasicExample():
  15. class ExampleTest extends TestCase {
  16. /**
  17. * A basic functional test example.
  18. *
  19. * @return void
  20. */
  21. public function testBasicExample()
  22. {
  23. $crawler = $this->client->request('GET', '/');
  24. $this->assertTrue($this->client->getResponse()->isOk());
  25. self::my_test();//your method
  26. }
  27. public function my_test()
  28. {
  29. echo 'Hi I want to show you some test results :)';
  30. }
  31. }

8. Save and close the file and run again 'vendor\bin\phpunit'.And you will see output like this:

PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from F:\laravel\laravelScrapbook\phpunit.xml

.Hi I want to show you test results :)

Time: 172 ms, Memory: 5.50Mb

←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K