json-snapshot.github.io icon indicating copy to clipboard operation
json-snapshot.github.io copied to clipboard

Does this work with TestNG?

Open geekyme opened this issue 4 years ago • 0 comments

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();
  }
}

geekyme avatar Sep 30 '19 04:09 geekyme