Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a simple test runner #99

Closed
Tracked by #95
derevnjuk opened this issue Dec 8, 2022 · 0 comments · Fixed by #111
Closed
Tracked by #95

Implement a simple test runner #99

derevnjuk opened this issue Dec 8, 2022 · 0 comments · Fixed by #111
Assignees
Labels
Type: enhancement New feature or request.

Comments

@derevnjuk
Copy link
Member

derevnjuk commented Dec 8, 2022

We should provide a simple implementation for the test runner that can look like this:

public interface SecRunner 
{
  Task Init();

  SecScan CreateScan(SecScanOptions options);

  Task clear();
}

There are multiple strategies for how to run tests: before-all or before-each (recommended).

The two most viable options are running before all the tests vs running before every single test. The implementation should allow us to utilize them both, to give users more freedom to decide how to run tests.

Below you can find the implementation of the before-each strategy:

public class TestFixture : IDisposable
{
  public SecRunnerFixture SecRunnerFixture { get; private set; }
  
  public TestFixture()
  {
    var hostname = ConfigurationManager.AppSettings["BrigthHost"];
    SecRunnerFixture = new SecRunnerFixture(hostname);
  }
  
  public void Dispose()
  {
    SecRunnerFixture.Dispose();
  }
  
  public class SecRunnerFixture : IDisposable
  {
    public SecRunner Runner { get; private set; }
    public SecRunnerFixture(string hostname)
    {
      Runner = new SecRunner(hostname);

      // initialize data runner
    }

    public void Dispose()
    {
      // clean up runner
    }
  }
}

public class OrdersApiTests : IClassFixture<TestFixture>
{
  TestFixture _fixture;
  
  public OrdersApiTests(TestFixture fixture)
  {
      _fixture = fixture;
  }
    
  [Fact]
  public async Task Post_when_order_succeed_send_mail_to_store_manager()
  {
    var runner = _fixture.SecRunnerFixture.Runner;
    var options = new ScanOptions {
      tests = {TestType.XSS}
    };
    
    var scan = runner
      .createScan(options)
      .threshold(Severity.MEDIUM) // i. e. ignore LOW severity issues
      .timeout(300000); // i. e. fail if last longer than 5 minutes
      
    // run test here
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant