總網頁瀏覽量

關於我自己

我的相片
人生的必修課是接受無常,人生的選修課是放下執著。

2017年2月3日 星期五

【Windows 7 64-bit】【Eclipse Juno】【JUnit 4】從下載到第一個Test Case

1 下載Eclipse Juno版


https://eclipse.org/downloads/packages/release/juno/sr2


2 下載完成後→解壓縮→執行eclipse.exe


3 建立專案

Eclipse -> File -> New -> Java Project
(1) Package Name:yu7
(2) Finish

在package上點右鍵,New -> JUnit Test Case
(1) 選New JUnit Test Case
(2) Package:org.openyu.java.junit
(3) Name:JunitTest
(4) 勾選
(5) Finish




4 程式碼

package org.openyu.java.junit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class JunitTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void test() {
 System.out.println("---------------------------");
 System.out.println("test java.openyu.org");
 System.out.println("---------------------------");
}


}


5 在JUnit Test Case上按滑鼠右鍵→Run As→JUnit Test



6 執行結果



參考:http://java.openyu.org/2014/02/junit1-eclipsetest-case.html





2017年1月15日 星期日

【invisionapp】免費建立手機模擬器


Google搜尋關鍵字:invisionapp


首頁:https://www.invisionapp.com/

註冊新帳號:填妥「NAME」、「EMAIL ADDRESS」、「PASSWORD」→Click「SIGN UP FREE」button

Click「STAR FIRST PROJECT」button

Click「CREATE NEW PROTOTYPE」button

Input PROJECT NAME and choose the type of emulator→Click「GET STARTED」button

Click「browse」to choose psd、pdf、png、jpg、gif file


After upload one picture, Click「VIEW SCREEN」button

Click「BUILD MODE」button

接著可以框選範圍,進一步指定當User Click框選範圍後執行的動作

再選一張圖上傳,作為Click框選範圍後要開啟的圖片

點一下圖片就可以設定好了




選好「Gesture」和「Transition」後→Click「SAVE」button

滑鼠移到框選範圍上,看到提示訊息「SHIFT + Click to Navigate」=按下鍵盤Shift鍵+滑鼠點一一下框選範圍就可以切換到所連接的圖片

另外裝置上超出螢幕的內容,可以用Photoshop接成一張大圖,超過螢幕畫面的部分可以作滑動。


------------------------------------------------------------------------------------------------------------------
【分享網址給他人】



會得到一個短網址。EX:https://invis.io/PF9X43NXY


開新分頁貼上,會自動轉成一般網址讀取內容










2017年1月9日 星期一

現行Android版本市占率 - 2017.01.09

查詢網站:
https://developer.android.com/about/dashboards/index.html#platform



API Level OS CodeName Distributionn
1 1.0    
2 1.1    
3 1.5 Cupcake  
4 1.6 Donut  
5 2.0 Éclair  
6 2.0.1 Éclair  
7 2.1 Éclair  
8 2.2 Froyo  
9 2.3    
10 2.3.3   1.0%
11 3.0    
12 3.1 Gingerbread  
13      
14      
15 4.0.3 ICSandwich  1.1%
16 4.1.x Jelly Bean 4.0%
17 4.2.x Jelly Bean 5.90%
18 4.3 Jelly Bean 1.70%
19 4.4 kitkak 22.60%
20      
21 5.0 Lollipop 10.10%
22 5.1   23.30%
23 6.0 Marshmallow 29.60%
24 7.0 Nougat 0.50%
25 7.1   0.20%

2016年11月7日 星期一

【adb】【Windows】無法找到裝置時下載ADB Driver Installer

電腦端要安裝手機的驅動程式,HTC手機請安裝HTC Sync,MOTO手機請安裝Motorola USB drivers,Samsung手機請安裝Kies,SONY手機請安裝Xperia Companion。

【萬用】下載 ADB Driver Installer.exe 執行檔以自動安裝不同廠牌手機Android ADB Interface的驅動程式


下載後執行

指令adb kill-server與adb devices可以找到Device了!!!
  • 手機端要開啟「USB除錯」,進入手機設定>應用程式>開發>勾選USB除錯

    本例中使用HTC手機
  • 2016年11月2日 星期三

    【RobotFramework】【Sample】QuickStartGuide-master.zip

    1. 下載sample code
     https://github.com/robotframework/QuickStartGuide/archive/master.zip

    2. The recommended approach to install Robot Framework on Python is using pip. 
     開啟命令提示字元,用pip安裝robotframework
    pip install robotframework

    3. This demo is written using reStructuredText markup language with Robot Framework test data in code blocks.
     開啟命令提示字元,用pip安裝docutils
    pip install docutils
    4-1. 開啟命令提示字元,執行測試
    robot QuickStart.rst

    report.html
    Higher level test report.
    log.html
    Detailed test execution log.
    output.xml
    Results in machine readable XML format.

    4-2. If you use Robot Framework 2.9 or older, instead of the robot command you need to use pybot:
    但如果你的Robot Framework版本舊於2.9,可以用pybot來執行QuickStart.rst
    pybot QuickStart.rst

    5. You can also configure the execution with various command line options:
    在執行的同時,可以另存一份自己命名的log檔
    robot --log custom_log.html --name Custom_Name QuickStart.rst
    ----------------以下為程式碼相關說明----------------

    Test cases

    Workflow tests

    Robot Framework test cases are created using a simple tabular syntax. For example, the following table has two tests:
    • User can create an account and log in
    • User cannot log in with bad password
    *** Test Cases ***
    User can create an account and log in
        Create Valid User    fred    P4ssw0rd
        Attempt to Login with Credentials    fred    P4ssw0rd
        Status Should Be    Logged In
    
    User cannot log in with bad password
        Create Valid User    betty    P4ssw0rd
        Attempt to Login with Credentials    betty    wrong
        Status Should Be    Access Denied
    Notice that these tests read like manual tests written in English rather than like automated test cases. Robot Framework uses the keyword-driven approach that supports writing tests that capture the essence of the actions and expectations in natural language.
    Test cases are constructed from keywords and their possible arguments. The syntax requires that keywords and arguments, as well as settings and their values, are separated by at least two spaces or by a tab character. It is generally recommended to use four spaces to make the separator more explicit, and in some cases aligning arguments or other values may make the data easier to understand. For more details about the syntax see Robot Framework User Guide.

    Higher-level tests

    Test cases can also be created using only high-level keywords that take no positional arguments. This style allows using totally free text which is suitable for communication even with non-technical customers or other project stakeholders. This is especially important when using the acceptance test-driven development (ATDD) approach or any of its variants and created tests act also as requirements.
    Robot Framework does not enforce any particular style for writing test cases. One common style is the given-when-thenformat popularized by behavior-driven development (BDD):
    *** Test Cases ***
    User can change password
        Given a user has a valid account
        When she changes her password
        Then she can log in with the new password
        And she cannot use the old password anymore

    Data-driven tests

    Quite often several test cases are otherwise similar but they have slightly different input or output data. In these situations data-driven tests allows varying the test data without duplicating the workflow. With Robot Framework the [Template]setting turns a test case into a data-driven test where the template keyword is executed using the data defined in the test case body:
    *** Test Cases ***
    Invalid password
        [Template]    Creating user with invalid password should fail
        abCD5            ${PWD INVALID LENGTH}
        abCD567890123    ${PWD INVALID LENGTH}
        123DEFG          ${PWD INVALID CONTENT}
        abcd56789        ${PWD INVALID CONTENT}
        AbCdEfGh         ${PWD INVALID CONTENT}
        abCD56+          ${PWD INVALID CONTENT}
    In addition to using the [Template] setting with individual tests, it would be possible to use the Test Template setting once in the setting table like setups and teardowns are defined in this guide later. In our case that would ease creating separate and separately named tests for too short and too long passwords and for other invalid cases. That would require moving those tests to a separate file, though, because otherwise the common template would be applied also to other tests in this file.
    Notice also that the error messages in the above example are specified using variables.

    Keywords

    Test cases are created from keywords that can come from two sources. Library keywords come from imported test libraries, and so called user keywords can be created using the same tabular syntax that is used for creating test cases.

    Library keywords

    All lowest level keywords are defined in test libraries which are implemented using standard programming languages, typically Python or Java. Robot Framework comes with a handful of test libraries that can be divided to standard libraries, external libraries and custom libraries. Standard libraries are distributed with the core framework and included generic libraries such as OperatingSystem, Screenshot and BuiltIn, which is special because its keywords are available automatically. External libraries, such as Selenium2Library for web testing, must be installed separately. If available test libraries are not enough, it is easy to create custom test libraries.
    To be able to use keywords provided by a test library, it must be taken into use. Tests in this guide need keywords from the standard OperatingSystem library (e.g. Remove File) and from a custom made LoginLibrary (e.g. Attempt to login with credentials). Both of these libraries are imported in the setting table below:
    *** Settings ***
    Library           OperatingSystem
    Library           lib/LoginLibrary.py

    User keywords

    One of the most powerful features of Robot Framework is the ability to easily create new higher-level keywords from other keywords. The syntax for creating these so called user-defined keywords, or user keywords for short, is similar to the syntax that is used for creating test cases. All the higher-level keywords needed in previous test cases are created in this keyword table:
    *** Keywords ***
    Clear login database
        Remove file    ${DATABASE FILE}
    
    Create valid user
        [Arguments]    ${username}    ${password}
        Create user    ${username}    ${password}
        Status should be    SUCCESS
    
    Creating user with invalid password should fail
        [Arguments]    ${password}    ${error}
        Create user    example    ${password}
        Status should be    Creating user failed: ${error}
    
    Login
        [Arguments]    ${username}    ${password}
        Attempt to login with credentials    ${username}    ${password}
        Status should be    Logged In
    
    # Keywords below used by higher level tests. Notice how given/when/then/and
    # prefixes can be dropped. And this is a comment.
    
    A user has a valid account
        Create valid user    ${USERNAME}    ${PASSWORD}
    
    She changes her password
        Change password    ${USERNAME}    ${PASSWORD}    ${NEW PASSWORD}
        Status should be    SUCCESS
    
    She can log in with the new password
        Login    ${USERNAME}    ${NEW PASSWORD}
    
    She cannot use the old password anymore
        Attempt to login with credentials    ${USERNAME}    ${PASSWORD}
        Status should be    Access Denied
    User-defined keywords can include actions defined by other user-defined or library keywords. As you can see from this example, user-defined keywords can take parameters. They can also return values and even contain FOR loops. For now, the important thing to know is that user-defined keywords enable test creators to create reusable steps for common action sequences. User-defined keywords can also help the test author keep the tests as readable as possible and use appropriate abstraction levels in different situations.

    Variables

    Defining variables

    Variables are an integral part of Robot Framework. Usually any data used in tests that is subject to change is best defined as variables. Syntax for variable definition is quite simple, as seen in this variable table:
    *** Variables ***
    ${USERNAME}               janedoe
    ${PASSWORD}               J4n3D0e
    ${NEW PASSWORD}           e0D3n4J
    ${DATABASE FILE}          ${TEMPDIR}${/}robotframework-quickstart-db.txt
    ${PWD INVALID LENGTH}     Password must be 7-12 characters long
    ${PWD INVALID CONTENT}    Password must be a combination of lowercase and uppercase letters and numbers
    Variables can also be given from the command line which is useful if the tests need to be executed in different environments. For example this demo can be executed like:
    robot --variable USERNAME:johndoe --variable PASSWORD:J0hnD0e QuickStart.rst
    
    In addition to user defined variables, there are some built-in variables that are always available. These variables include ${TEMPDIR} and ${/} which are used in the above example.

    Using variables

    Variables can be used in most places in the test data. They are most commonly used as arguments to keywords like the following test case demonstrates. Return values from keywords can also be assigned to variables and used later. For example, the following Database Should Contain user keyword sets database content to ${database} variable and then verifies the content using BuiltIn keyword Should Contain. Both library and user keywords can return values.
    *** Test Cases ***
    User status is stored in database
        [Tags]    variables    database
        Create Valid User    ${USERNAME}    ${PASSWORD}
        Database Should Contain    ${USERNAME}    ${PASSWORD}    Inactive
        Login    ${USERNAME}    ${PASSWORD}
        Database Should Contain    ${USERNAME}    ${PASSWORD}    Active
    
    *** Keywords ***
    Database Should Contain
        [Arguments]    ${username}    ${password}    ${status}
        ${database} =     Get File    ${DATABASE FILE}
        Should Contain    ${database}    ${username}\t${password}\t${status}\n

    Organizing test cases

    Test suites

    Collections of test cases are called test suites in Robot Framework. Every input file which contains test cases forms a test suite. When executing this guide, you see test suite QuickStart in the console output. This name is got from the file name and it is also visible in reports and logs.
    It is possible to organize test cases hierarchically by placing test case files into directories and these directories into other directories. All these directories automatically create higher level test suites that get their names from directory names. Since test suites are just files and directories, they are trivially placed into any version control system.

    Setups and teardowns

    If you want certain keywords to be executed before or after each test, use the Test Setup and Test Teardown settings in the setting table. Similarly you can use the Suite Setup and Suite Teardown settings to specify keywords to be executed before or after an entire test suite.
    Individual tests can also have a custom setup or teardown by using [Setup] and [Teardown] in the test case table. This works the same way as [Template] was used earlier with data-driven tests.
    In this demo we want to make sure the database is cleared before execution starts and that every test also clears it afterwards:
    *** Settings ***
    Suite Setup       Clear Login Database
    Test Teardown     Clear Login Database

    Using tags

    Robot Framework allows setting tags for test cases to give them free metadata. Tags can be set for all test cases in a file with Force Tags and Default Tags settings like in the table below. It is also possible to define tags for a single test case using [Tags] settings like in earlier User status is stored in database test.
    *** Settings ***
    Force Tags        quickstart
    Default Tags      example    smoke
    When you look at a report after test execution, you can see that tests have specified tags associated with them and there are also statistics generated based on tags. Tags can also be used for many other purposes, one of the most important being the possibility to select what tests to execute. You can try, for example, following commands:
    robot --include smoke QuickStart.rst
    robot --exclude database QuickStart.rst
    

    Creating test libraries

    Robot Framework offers a simple API for creating test libraries using either Python or Java, and the remote library interface allows using also other programming languages. Robot Framework User Guide contains detailed description about the library API.
    As an example, we can take a look at LoginLibrary test library used in this demo. The library is located at lib/LoginLibrary.py, and its source code is also copied below. Looking at the code you can see, for example, how the keyword Create User is mapped to actual implementation of method create_user.

    import os.path
    import subprocess
    import sys
    
    
    class LoginLibrary(object):
    
        def __init__(self):
            self._sut_path = os.path.join(os.path.dirname(__file__),
                                          '..', 'sut', 'login.py')
            self._status = ''
    
        def create_user(self, username, password):
            self._run_command('create', username, password)
    
        def change_password(self, username, old_pwd, new_pwd):
            self._run_command('change-password', username, old_pwd, new_pwd)
    
        def attempt_to_login_with_credentials(self, username, password):
            self._run_command('login', username, password)
    
        def status_should_be(self, expected_status):
            if expected_status != self._status:
                raise AssertionError("Expected status to be '%s' but was '%s'."
                                     % (expected_status, self._status))
    
        def _run_command(self, command, *args):
            command = [sys.executable, self._sut_path, command] + list(args)
            process = subprocess.Popen(command, stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT)
            self._status = process.communicate()[0].strip()

    ----------------以上為程式碼相關說明----------------