github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/docs/quickstart.md (about)

     1  # Tast Quickstart (go/tast-quickstart)
     2  
     3  [TOC]
     4  
     5  ## Prerequisites
     6  
     7  You'll need a [ChromeOS chroot]. If you've only done Chrome development so far,
     8  note that this is different from the Chrome checkout described in the
     9  [Simple Chrome] documentation.
    10  
    11  You'll also need a ChromeOS device running a system image built with the `test`
    12  flag that's reachable from your workstation via SSH. An image running in a
    13  [virtual machine] will also work. If you're using a test image that you
    14  downloaded rather than one built in your chroot, make sure that it's a recent
    15  version.
    16  
    17  <a name="dataloss"></a> **WARNING: Potential data loss:**  Many Tast tests
    18  remove all user profiles from the device when run, including any local state.
    19  Prefer to have a device specifically for testing.
    20  
    21  [ChromeOS chroot]: http://www.chromium.org/chromium-os/quick-start-guide
    22  [Simple Chrome]: https://chromium.googlesource.com/chromiumos/docs/+/main/simple_chrome_workflow.md
    23  [virtual machine]: https://chromium.googlesource.com/chromiumos/docs/+/main/cros_vm.md
    24  
    25  ## Setup
    26  
    27  ### Update ChromeOS chroot
    28  
    29  Assuming that you already have a valid ChromeOS repo checked out (see
    30  [ChromeOS chroot]), it is recommended to update the chroot by doing:
    31  
    32  ```sh
    33  cd ${CHROMEOS_SRC}
    34  chromite/bin/cros_sdk    # to enter chroot
    35  ./update_chroot          # makes sure that the latest dependencies are installed
    36  ```
    37  
    38  ### IDE
    39  
    40  Any [modern editor] supports Go. The following are the instructions to setup
    41  [Visual Studio Code] with Tast code navigation:
    42  
    43  1.  Download [Visual Studio Code]
    44  2.  Install the [official Go extension] (VSCode will recommend that extension
    45      once you open a Go file), and optionally [CrOS IDE], which [among others]
    46      substitutes the step 3 and 4 once you open a Tast test file.
    47  3.  Update the `GOPATH` environment variable to make code navigation works (`F12` key)
    48  
    49      ```sh
    50      mkdir ~/go
    51      # Main GOPATH, where extra binaries will get installed.
    52      export GOPATH=$HOME/go
    53      # Append Tast repos to GOPATH
    54      export GOPATH=${GOPATH}:${CHROMEOS_SRC}/src/platform/tast-tests:${CHROMEOS_SRC}/src/platform/tast
    55      # Append Tast dependencies
    56      export GOPATH=${GOPATH}:${CHROMEOS_SRC}/chroot/usr/lib/gopath
    57      ```
    58  
    59  4.  Start Visual Studio Code with Tast
    60  
    61      ```sh
    62      cd ${CHROMEOS_SRC}/src/platform/
    63      code ./tast-tests ./tast
    64      ```
    65  
    66  Note: If you are using the VSCode "Remote-SSH" extension, restart
    67  VSCode's SSH server after setting the GOPATH, otherwise the Go
    68  extension won't pick it up. For example, using the VSCode command
    69  palette, you can run `>Remote-SSH: Kill VS Code Server on Host`.
    70  
    71  After that, it's useful to add the following to your settings JSON to
    72  avoid opening a 404 page whenever you try to follow links from import
    73  statements:
    74  
    75  ```
    76    "gopls": {
    77      "ui.navigation.importShortcut": "Definition"
    78    },
    79  ```
    80  
    81  https://github.com/golang/vscode-go/issues/237#issuecomment-646067281
    82  
    83  [modern editor]: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
    84  [Visual Studio Code]: https://code.visualstudio.com/
    85  [official Go extension]: https://code.visualstudio.com/docs/languages/go
    86  [CrOS IDE]: https://marketplace.visualstudio.com/items?itemName=Google.cros-ide
    87  [among others]: http://go/cros-ide-doc-tast-tests
    88  
    89  ## Run a prebuilt test
    90  
    91  **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
    92  local state.
    93  
    94  In your chroot, run the following:
    95  
    96  ```sh
    97  tast -verbose run -build=false <test-device-ip> login.Chrome
    98  ```
    99  
   100  You should see output scroll by on your workstation, and on the ChromeOS
   101  device, the test should log in and load a webpage. After the test is done, take
   102  a look at the results in `/tmp/tast/results/latest` in your chroot.
   103  
   104  ## Build and run a test
   105  
   106  **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
   107  local state.
   108  
   109  The previous step ran a test that was already built into your device's system
   110  image, but you can also use the `tast` command to quickly rebuild all tests and
   111  push them to the device.
   112  
   113  In your chroot, run the same command as before **but without the `-build=false`
   114  argument**:
   115  
   116  ```sh
   117  tast -verbose run <test-device-ip> login.Chrome
   118  ```
   119  
   120  This time, the command will take a bit longer (but build objects will be
   121  cached). The test should succeed again.
   122  
   123  See [Running Tests] for more information.
   124  
   125  [Running Tests]: running_tests.md
   126  
   127  ## Modify a test
   128  
   129  Now, let's modify the test. In your ChromeOS checkout, go to
   130  `src/platform/tast-tests/src/go.chromium.org/tast-tests/cros/local/bundles/cros/login` and open
   131  `chrome.go` (for convenience, there's also a `local_tests` symlink at the
   132  top of `tast-tests`). The `Chrome` function here will run directly on the
   133  test device.
   134  
   135  At the end of the function `testChromeLogin`, add the following code:
   136  
   137  ```go
   138  if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil {
   139  	s.Error("Failed to open page: ", err)
   140  }
   141  ```
   142  
   143  Back in your chroot, run `tast` again:
   144  
   145  ```sh
   146  tast -verbose run <test-device-ip> login.Chrome
   147  ```
   148  
   149  This time, the test should additionally open a Google search page.
   150  
   151  Return to the test file and add the following statement at the end of the
   152  function `testChromeLogin`:
   153  
   154  ```go
   155  s.Error("This is an intentional error")
   156  ```
   157  
   158  If you build and run the test again, you should see it fail.
   159  
   160  ## Next steps
   161  
   162  See [Writing Tests] for more information, and explore the
   163  [tast-tests repository] to see existing tests and related packages. [Codelab #1]
   164  walks through the creation of a simple test.
   165  
   166  Additional Tast documentation is available in the [tast repository].
   167  
   168  Many resources are available for learning more about Go. Here are a few:
   169  
   170  *   [A Tour of Go] - In-browser introduction to Go's core features.
   171  *   [Official Go documentation] - Package documentation, specifications, blog
   172      posts, and recorded talks.
   173  *   [Go at Google: Language Design in the Service of Software Engineering] -
   174      High-level overview of Go's features and design philosophy.
   175  *   [Community Learn wiki] - Links to external resources.
   176  
   177  [Writing Tests]: writing_tests.md
   178  [tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/
   179  [Codelab #1]: codelab_1.md
   180  [tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/
   181  [A Tour of Go]: https://tour.golang.org/
   182  [Official Go documentation]: https://golang.org/doc/
   183  [Go at Google: Language Design in the Service of Software Engineering]: https://talks.golang.org/2012/splash.article
   184  [Community Learn wiki]: https://github.com/golang/go/wiki/Learn