Как я могу получить покрытие кода сторонних/внешних библиотек). Мой проект коснулся? [дублировать]JAVA

Программисты JAVA общаются здесь
Anonymous
Как я могу получить покрытие кода сторонних/внешних библиотек). Мой проект коснулся? [дублировать]

Сообщение Anonymous »

Я не экспертный разработчик, а исследователь PhD, повторяя эксперимент. Я знаю, что могу получить покрытие кода моего проекта с помощью Jacoco. Но я хочу покрыть код сторонней или внешней библиотеки (IES), который мой проект коснулся (с помощью Jacoco). < /P>

Код: Выделить всё

package com.example;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.security.AnyTypePermission;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.io.*;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;

public class App {
@Benchmark
@Warmup(iterations = 2, time = 3)
@Measurement(iterations = 2, time = 5)
// @BenchmarkMode(Mode.AverageTime)
@BenchmarkMode({ Mode.All })
@OutputTimeUnit(TimeUnit.SECONDS)
public Void benchmarkSerializationWithGSON(Blackhole bh) {
try {
Energy j = new Energy();
j.init();
XStream xstream = new XStream(new StaxDriver());
xstream.addPermission(AnyTypePermission.ANY);
xstream.alias("row", AUser.class);
xstream.alias("friend", Friend.class);
xstream.alias("root", AUser[].class);
xstream.addImplicitCollection(AUser.class, "tags", String.class);
xstream.addImplicitCollection(AUser.class, "friends", Friend.class);
File xmlFile = new File("./users5000-10.xml");
AUser[] users = (AUser[]) xstream.fromXML(new FileInputStream(xmlFile));
Writer writer = new FileWriter(new File("./marshalled"));
writer.write(xstream.toXML(users));
writer.close();
j.stop();
System.out.print(j.getEnergy() + "+ ");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public static void main(String...  args) throws Exception {
Options opts = new OptionsBuilder()
.include(App.class.getSimpleName())
// .resultFormat(ResultFormatType.CSV)
// .result("../assigned_tasks/Final-Results/XSTREAM-Results/result.csv")
// .jvmArgsAppend("-javaagent:target/jacoco-agent.jar")

.forks(1)
.build();
new Runner(opts).run();
}
}
Как показано выше, я хочу получить покрытие кода библиотеки Xstream, упомянутую как операторы импорта.

Код: Выделить всё

package com.example;

public class Driver {
public static void main(String[] args) {
try {
App.main(args); // Call to main method that throws Exception
} catch (Exception e) {
e.printStackTrace();
}
}
}

src/test/java/com/example/drivertest.java

Код: Выделить всё

package com.example;

import org.junit.jupiter.api.Test;

public class DriverTest {
@Test
public void testDriverMain() throws Exception {
Driver.main(new String[0]);  // runs your app
}
}
pom.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.example
JMH-Benchmark
MWK



1.8
1.8
1.8
UTF-8






com.thoughtworks.xstream
xstream
1.4.21




org.junit.jupiter
junit-jupiter-api
5.8.2
test


org.junit.jupiter
junit-jupiter-engine
5.8.2
test



junit
junit
4.13.2
test



org.mockito
mockito-core
4.5.1
test



org.openjdk.jmh
jmh-core
1.37


org.openjdk.jmh
jmh-generator-annprocess
1.37
provided








org.jacoco
jacoco-maven-plugin
0.8.10



prepare-agent



report
verify

report













org.codehaus.mojo
exec-maven-plugin
3.1.0



org.apache.maven.plugins
maven-compiler-plugin
3.8.0

${javac.target}
${javac.target}
${javac.target}



org.apache.maven.plugins
maven-shade-plugin
3.2.1


package

shade


${uberjar.name}


com.example.App






*:*

META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA











maven-clean-plugin
2.5


maven-deploy-plugin
2.8.1


maven-install-plugin
2.5.1


maven-jar-plugin
2.4



com.example.App





maven-javadoc-plugin
2.9.1


maven-resources-plugin
2.6


maven-site-plugin
3.3


maven-source-plugin
2.2.1


maven-surefire-plugin
2.17





< /code>
Я прошлой пару недель, я пытался много разных способов получить охват кода сторонней библиотеки (IES), но не получил, например, библиотека xstream. ко многим аспектам вопросов. Через 8 лет были бы пришли способы достичь этого с помощью муравья или любой сложности. Вот почему я снова разместил этот вопрос для рассмотрения.


Подробнее здесь: https://stackoverflow.com/questions/796 ... -project-t

Вернуться в «JAVA»