# Setup VS Code to run rails test

Either you use [RSpec](https://rspec.info/) or [Mini test](https://guides.rubyonrails.org/testing.html) you want an easy way to run the test file you are working on, or you might like to run the test under cursor to quickly validate if the test are passing. Most of the time we run `rails test` command manually in the terminal and its time consuming. For vim users there are so many great vim plugins like [vim-test](https://github.com/vim-test/vim-test).

In this article I am going to show you how you can easily setup a keybinding without using any additional VS code plugins to run tests directly from your editor.

* Open a [visual studio code](https://code.visualstudio.com/).
    
* Click on setting -&gt; Keyboard shortcuts (you can also use `ctrl/cmd K, ctrl/cmd S`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724829656226/6e32f14b-a966-4793-8d98-fa37b3ebc51e.png align="center")
    
    * Open the setting file by clicking on the file icon at top right corner
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724829719837/ff9912d8-db2c-449c-9d3c-2df77d691a89.png align="center")
        
    * And add following 2 shortcuts, you can change the shortcut keys as you like, or add more if you want to run all the test cases
        
    * ```json
        {
            // run all tests in current test file
            "key": "shift+cmd+r",
            "command": "workbench.action.terminal.sendSequence",
            "args": { "text": "bin/rails test ${relativeFile}\u000D" }
          },
          {
            // Run test at current line
            "key": "shift+cmd+i",
            "command": "workbench.action.terminal.sendSequence",
            "args": { "text": "bin/rails test ${relativeFile}:${lineNumber}\u000D" }
          }
        ```
        
* Open your terminal `ctrl/cmd ~` and also open your test file
    
* You can use these shortcuts `shift + cmd/ctrl + r` to run all tests under current file
    
* Or use `shift + cmd/ctrl + i` to run specific test under cursor.
    

Enjoy!!
