Skip to content

Does this work with TestNG? #26

Open
@geekyme

Description

@geekyme

I'm using TestNG instead of JUnit and I'm encountering some errors:

Gradle suite > Gradle test > com.snapshottest.demo.DemoApplicationTests > beforeAll FAILED
    java.lang.IllegalArgumentException at DemoApplicationTests.java:20
        Caused by: java.lang.ClassNotFoundException at DemoApplicationTests.java:20

Sample test class below:

package com.snapshottest.demo;

import io.github.jsonSnapshot.SnapshotMatcher;
import io.restassured.http.ContentType;
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
import static io.restassured.RestAssured.given;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = SpringRunner.class)
public class DemoApplicationTests {
  @BeforeClass
  public static void beforeAll() {
    SnapshotMatcher.start();
  }

  @AfterClass
  public static void afterAll() {
    SnapshotMatcher.validateSnapshots();
  }

	@Test
	public void contextLoads() {
  }

  @Test 
  public void dummyApiHas200() {
    RestAssured.defaultParser = Parser.JSON;

    String response = given()
      .contentType(ContentType.JSON)
      .when()
      .get("http://dummy.restapiexample.com/api/v1/employees")
      .then()
      .statusCode(200)
      .extract()
      .response()
      .asString();
    
    SnapshotMatcher.expect(response).toMatchSnapshot();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions