Rewrite specific action url

It’s not clear from your question how important it is that the query string is action and the value test, but if all you need to do is have a /test URL, and be able to tell if it’s the /test URL so that you can process soemthing, then the simplest way is probably to use add_rewrite_endpoint(). That would look like this:

function wpse_279663_rewrite_test() {
    add_rewrite_endpoint( 'test', EP_ROOT ); 
}
add_action( 'init', 'wpse_279663_rewrite_test' );

Now http://example.com/test will rewrite to http://example.com/?test=. Then you can use get_query_var() to see if ?test is set:

if ( get_query_var( 'test', false ) !== false ) {}

The 2nd argument says that if 'test' is not set then return false (the default is an empty string, which is useless in this case) so that we can see if it’s set or not with a simple true/false.

One way you could use this is in the init hook, to process a form or something, like this:

function wpse_279663_test() {
    if ( get_query_var( 'test', false ) !== false ) {
        // Do something.
    }
}
add_action( 'init', 'wpse_279663_test' );