-
Notifications
You must be signed in to change notification settings - Fork 293
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
[WIP] Add file attribute to JUnit reports #8216
base: master
Are you sure you want to change the base?
Changes from all commits
8088396
fa98ca9
25d4ade
2e00794
2d66a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
datadog.context.GetSourceFileInfoExtension |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package datadog.context; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.TestInstancePostProcessor; | ||
|
||
public class GetSourceFileInfoExtension implements TestInstancePostProcessor { | ||
private static Map<String, String> sourceFiles = new HashMap<String, String>(); | ||
|
||
@Override | ||
public void postProcessTestInstance(Object testInstance, ExtensionContext context) | ||
throws IOException { | ||
getTestData(context); | ||
} | ||
|
||
public static Map<String, String> getSourceFiles() { | ||
return sourceFiles; | ||
} | ||
|
||
private static void getTestData(ExtensionContext context) throws IOException { | ||
// get test classname and source file | ||
String testClassName = context.getTestClass().get().getName(); | ||
String testClassPath = testClassName.replace(".", "/") + ".java"; | ||
String root = Paths.get("").toAbsolutePath().toString(); | ||
String absolutePath = root + "/src/test/java/" + testClassPath; | ||
String subPath = | ||
absolutePath.substring(absolutePath.indexOf("dd-trace-java") + "dd-trace-java".length()); | ||
|
||
// print to sourceFiles.xml only if source file has not already been added | ||
if (!sourceFiles.containsKey(testClassName)) { | ||
File sourceFile = new File(root + "/build/test-results/sourceFiles.xml"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we're not outputting here XML, but some custom format? We should use something like |
||
if (!sourceFile.exists()) { | ||
sourceFile.createNewFile(); | ||
} | ||
BufferedWriter writer = new BufferedWriter(new FileWriter(sourceFile, true)); | ||
writer.write(testClassName + ":" + subPath); | ||
writer.newLine(); | ||
writer.close(); | ||
} | ||
sourceFiles.put(testClassName, subPath); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,20 @@ apply plugin: 'datadog.dependency-locking' | |
|
||
apply from: "$rootDir/gradle/java_deps.gradle" | ||
apply from: "$rootDir/gradle/java_no_deps.gradle" | ||
|
||
tasks.named("test") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's more test tasks than these two. You may use something like:
to make sure this runs after all of them. |
||
finalizedBy("myCustomTask") | ||
} | ||
|
||
tasks.named("forkedTest") { | ||
finalizedBy("myCustomTask") | ||
} | ||
|
||
tasks.register('myCustomTask') { | ||
group = "Custom Tasks" // Optional, for better organization | ||
description = "This is a custom task that prints a message" | ||
|
||
doLast { | ||
println("Running my custom task!") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension should probably live at
./utils/test-utils
.