Skip to content

Commit

Permalink
Allow to work directly with Result object inside JUnit test for addin…
Browse files Browse the repository at this point in the history
…g notes, links, types etc.

Update to ReesmoWriter 0.1.0
  • Loading branch information
zkaetn committed Mar 11, 2016
1 parent 99739eb commit 09dbe14
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>cz.etnetera</groupId>
<artifactId>reesmo-adapter-junit</artifactId>
<version>0.0.2</version>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>Reesmo Java Adapter JUnit</name>
Expand Down Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>cz.etnetera</groupId>
<artifactId>reesmo-writer</artifactId>
<version>0.0.1</version>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;

import cz.etnetera.reesmo.writer.model.result.Result;
import cz.etnetera.reesmo.writer.storage.FileWithPath;

/**
Expand Down Expand Up @@ -51,4 +52,18 @@ public void addAttachment(FileWithPath file) {
listener.getAttachments(resultKey).add(file);
}

/**
* Returns instance of Result which will be stored
* in Reesmo. Feel free to add specific values,
* i.e. notes, labels, categories, types, links etc.
*
* Only attachments need to be added separately using
* {@link ReesmoJUnitBridge#addAttachment(File)} like methods.
*
* @return
*/
public Result getResult() {
return listener.getResult(resultKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public class ReesmoJUnitExecutionListener extends RunListener {
protected Map<String, List<Object>> attachmentsMap = new ConcurrentHashMap<>();

public void initTest(ReesmoJUnitTest testClassInstance, FrameworkMethod testMethod) {
String resultKey = getResultKey(testClassInstance.getClass().getName(), testMethod.getName());
String resultKey = getResultKey(testClassInstance.getClass(), testMethod.getName());
testClassInstance.registerReesmoBridge(new ReesmoJUnitBridge(resultKey, this));
}

@Override
public void testStarted(Description description) throws Exception {
Result result = getResult(description);
result.setName(getResultName(description));
result.setStartedAt(new Date());
result.setAutomated(true);
Suite suite = getSuite(description);
Expand Down Expand Up @@ -103,6 +104,7 @@ public void testAssumptionFailure(Failure failure) {
@Override
public void testIgnored(Description description) throws Exception {
Result result = getResult(description);
result.setName(getResultName(description));
result.setStartedAt(new Date());
result.setEndedAt(result.getEndedAt());
result.setAutomated(true);
Expand All @@ -114,20 +116,18 @@ public void testIgnored(Description description) throws Exception {
}

protected Result getResult(Description description) {
String key = getResultKey(description);
Result result = resultsMap.get(key);
return getResult(getResultKey(description));
}

protected Result getResult(String resultKey) {
Result result = resultsMap.get(resultKey);
if (result == null) {
result = new Result();
result.setName(getResultName(description));
resultsMap.put(key, result);
resultsMap.put(resultKey, result);
}
return result;
}

protected void setResult(Description description, Result result) {
resultsMap.put(getResultKey(description), result);
}

protected Suite getSuite(Description description) {
String key = getSuiteKey(description);
Suite suite = suitesMap.get(key);
Expand All @@ -148,15 +148,19 @@ protected List<Object> getAttachments(String resultKey) {
}

protected String getResultKey(Description description) {
return getResultKey(description.getClassName(), description.getMethodName());
return getResultKey(description.getTestClass(), description.getMethodName());
}

protected String getResultKey(String className, String methodName) {
return className + "." + methodName;
protected String getResultKey(Class<?> testClass, String methodName) {
return testClass.getName() + "." + methodName;
}

protected String getResultName(Description description) {
return description.getTestClass().getSimpleName() + "." + description.getMethodName();
return getResultName(description.getTestClass(), description.getMethodName());
}

protected String getResultName(Class<?> testClass, String methodName) {
return testClass.getSimpleName() + "." + methodName;
}

protected String getSuiteKey(Description description) {
Expand Down

0 comments on commit 09dbe14

Please sign in to comment.