java - How to Clear instance filed afterClass in Junit? -


i looking way collect , publish these myresults. junit @afterclass supports static method.

if having super class if multiple test cases running can ugly. idea how can resolve this? if use after, won't full output collected myresult

abstract class maintestcase{   static list<string> myresults = new arraylist();    @afterclass public static void wrapup() {      //code write myresults text file  goes here     system.out.println("wrapping up");     myresults.clear()   }  }  @runwith(theories.class) public class theoryafterclasstest extends maintestcase {    @datapoint   public static string = "a";    @datapoint   public static string b = "bb";    @datapoint   public static string c = "ccc";    @theory   public void stringtest(string x, string y) {     myresults.add(x + " " + y);     system.out.println(x + " " + y);   }       } 

putting list<string> myresults; threadlocal may solve problem, how parallel test cases have own instance of myresults.

static threadlocal<list<string>> myresults = new threadlocal<>();  @beforeclass public static void setupclass() {     myresults.set(new arraylist<string>()); }  // use later in code @test public void mytestcase() {      myresults.get().add("result"); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -