I am unsure about what the error might be, any kind of help is appreciated.
I am trying to use - https://github.com/SpoonLabs/flacoco I clonned the repository and then
created a maven project through eclipse IDE and added the dependencies in the Pom file however when I create a main java file with the code below obtained from their video - https://www.youtube.com/watch?v=RFRyvQuwRYA&ab_channel=DavideGinelli and try to run it. It does not detect any tests. It displays the following.
[30] INFO CoverageRunner - Tests found: 0
[30] INFO CoverageRunner - Tests executed: 0
This is the code in my main.
package demoproject1;
import java.io.IOException;
import java.util.Map;
import fr.spoonlabs.flacoco.api.Flacoco;
import fr.spoonlabs.flacoco.api.result.FlacocoResult;
import fr.spoonlabs.flacoco.api.result.Suspiciousness;
import fr.spoonlabs.flacoco.core.config.FlacocoConfig;
import spoon.reflect.code.CtStatement;
public class Main {
public static void main(String[] args) throws IOException {
FlacocoConfig config = new FlacocoConfig();
config.setProjectPath("C:\\Users\\A\\Documents\\GitHub\\flacoco\\examples\\math_70"); //./examples/math_70
config.setComputeSpoonResults(true);
Flacoco flacoco = new Flacoco(config);
FlacocoResult result =flacoco.run();
Map<CtStatement, Suspiciousness> spoonMap = result.getSpoonSuspiciousnessMap();
for(Map.Entry<CtStatement, Suspiciousness> entry : spoonMap.entrySet()){
System.out.println(entry.getKey().getPosition()+":"+ entry.getValue().getScore());
}
}
}
I am unsure about what the error might be, any kind of help is appreciated.
I was also confused by this, but pretty sure you have to build the project you are trying to test. As per the paper:
"FLACOCO detects the tests to be executed and analyzed by scanning the compiled classes" (flacoco paper)
I was getting the same error, until I ran
mvn install
in the repository I was trying to test (in this case, it was examples/exampleFL1/FLtest1. Not sure if the authors just forgot to mention this explicitly (maybe they thought it would be obvious) or if they just had already built the projects they were testing. But, this is what worked for me.
Related
I am developing a simple calculator application in Java 8/9 in Eclipse. I am working on the power operation (as in "to the power of" used in math). I want to use the Math.power() instead of a for loop. However, I am having trouble importing the java math package into the program. The internet says to add import java.lang.math. When I try to code it in, I receive a notice of "Cannot Perform Operation. This compilation unit is not on the build path of the Java Project". What am I overlooking and/or doing wrong? Please provide suggestions or feedback.
Please note: Yes this is an academic assignment. To make this clear, I am not asking for the coding of the power operation. This issue is specifically about the importing the math package.
power operation (power.java)
package org.eclipse.example.calc.internal.operations;
import org.eclipse.example.calc.BinaryOperation;
// import java.lang.math; produces error
// Binary Power operation
public class Power extends AbstractOperation implements BinaryOperation {
// code removed. not relevant to SOF question.
}
Main (calculator.java)
package org.eclipse.example.calc.internal;
import org.eclipse.example.calc.BinaryOperation;
import org.eclipse.example.calc.Operation;
import org.eclipse.example.calc.Operations;
import org.eclipse.example.calc.UnaryOperation;
import org.eclipse.example.calc.internal.operations.Power;
import org.eclipse.example.calc.internal.operations.Equals;
import org.eclipse.example.calc.internal.operations.Minus;
import org.eclipse.example.calc.internal.operations.Plus;
import org.eclipse.example.calc.internal.operations.Divide;
import org.eclipse.example.calc.internal.operations.Square;
public class Calculator {
private TextProvider textProvider;
private String cmd;
private boolean clearText;
private float value;
public static String NAME = "Simple Calculator";
public Calculator(TextProvider textProvider) {
this.textProvider = textProvider;
setupDefaultOperations();
}
private void setupDefaultOperations() {
new Power();
new Equals();
new Minus();
new Plus();
new Divide();
new Square();
}
....
BTW, I use camel Case normally, but the academic project name everything including file names in standard writing format.
EDIT: After reading a response, I realized I forget to mention this. I can't get any further than typing import java., then the error pop-ups. Then I can't type the rest of the import statement
Image of package hierarchy
Your project is not configured correctly. You have no source dir at all. The src dir should be marked as source dir; right click it and tell eclipse about this, or, as it is a maven project, it's more likely a broken pom. Also, why are you using the org.eclipse package? If you work for SAP, it should be com.sap.
I'm on my first minecraft. I followed the documentation until the creation of the Main class. There has to be #Mod() but I can only input `value. In the documentation it says there has to be modid etc.
import net.minecraftforge.fml.common.Mod;
#Mod(modid = "test")
public class Main {
}
The error is:
Cannot resolve method 'modid'
The problem is strange. On github, the file has all those symbols but not on my machine. When I open the file (Mod.java) it only has „value“ but in the public forge fml repo it has all the fields
Try to restart the IDE or rebuild / clean the project
I'm practicing building a test automation framework using Selenium Webdrive in Eclipse with Java, and as part of this I'm debugging through the code I have written so that I have a full understanding (I should note that when I run my tests outside of debug mode they work fine). The issue I have is that I keep encountering 'Source not found' errors in debug mode in respect of a whole load of stuff.
I've attached a screenshot below which shows my debug window in Eclipse, and shows an example of one of the errors.
So, the situation is that I have my TestRunner class from where I am running my tests (see code below)
package dataStructureModel;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestRunner {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
List<iTest> tests = new ArrayList<iTest>();
// adding first test
tests.add((iTest) new DragDefaultTest001());
// adding second test
tests.add((iTest) new ColorCheckTest002());
BREAKPOINT HERE!
for(int i = 0; i < tests.size() ; i++)
{
iTest currentTest = tests.get(i);
currentTest.testSetup(driver);
boolean testResult = currentTest.runTest();
if(testResult)
{
System.out.println(currentTest.testName() + " test passed.");
}
else
{
System.out.println(currentTest.testName() + " test failed.");
}
currentTest.testCleanup();
}
}
}
I've set a breakpoint at the 'for' loop to iterate through my tests (I've not attached the code, given that as mentioned earlier, the tests do run). The Firefox browser loads up and I start stepping through and all looks good. Then I hit one of these 'Source not found' errors', of which there are many. I've attached a screenshot here, which gives an example....http://i.imgur.com/aDxCAX0.png
I know it asks to 'Edit Source Lookup Path', but I'm not sure what I should be referencing? As far as I'm aware I've attached all the selenium jar files, so I'm not sure where I'm going wrong.
This needs selenium-jar SOURCE files. In case you do no intend to see internals of Selenium Jars(which is a rare case), then just Step Over(F6) instead of Step Into(F5)
Hope this helps!
I'm doing a processing based project with eclipse and Procliping. When I'm testing the project with "Run" command inside the IDE, everything works fine. But if I export it into a runable-jar, when I run the jar it'll give this error on the line String[] li=Serial.list();. Any idea what's going wrong?
Java source attachment is "processing-2.2.1/modes/java/libraries/serial/src"
And here is a sample code:
package abcd;
import processing.core.PApplet;
import processing.serial.Serial;
public class TestUI extends PApplet {
Serial port;
public void setup(){
System.out.println(Serial.list());
}
public void draw(){
}
public static void main(String _args[]) {
PApplet.main(new String[] { abcd.TestUI.class.getName() });
}
}
My approach of solving it:
Download the latest version of java-simple-serial-connector(Which is the base library used for Processing's serial library), replace jssc.jar in the lib folder, and the error will be gone, and my application runs smoothly.
However the base library is 4 times bigger than the modified version used in Processing, so there may be some unnecessary features involved.
Seems like in their latest alpha version, Processing solved the same problem for exporting apps(at least in windows) by adding more look-up paths, while keeping their Serial library intact. I'm not familiar with their development environment, so I didn't look further into it. There may be a simpler solution.
I have some problem with using JMH.
So, I create an empty project in Intellij Idea, then in project structure add jmh-core jar file. Finally, try to run samples, for example
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
public class JMHSample_01_HelloWorld {
#GenerateMicroBenchmark
public void wellHelloThere() {
// this method was intentionally left blank.
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + JMHSample_01_HelloWorld.class.getSimpleName() + ".*")
.forks(1)
.build();
new Runner(opt).run();
}
}
but result is
No matching benchmarks. Miss-spelled regexp?
Use EXTRA verbose mode to debug the pattern matching.
Process finished with exit code 0
with using verbosity(VerboseMode.EXTRA)
No matching benchmarks. Miss-spelled regexp?
Benchmarks:
Process finished with exit code 0
I tried to change output path to projectFolder\target\classes but nothing was changed.
Then I looked at the source code in the debug mode and see that resource = "/META-INF/MicroBenchmarks",urls.hasMoreElements() is false and therefore benchmarks is empty. Then I saw at the samples jar file which has MicroBenchmarks file with information about tests and work well.
So, the question is what do I do wrong?
Do I have to write information about test manually?
Please follow the instructions on JMH page to set up the benchmark project, namely:
"Make sure you tried these things before getting support:
- Archetypes provide the golden build configuration. Try to generate the clean JMH benchmark project and transplant the benchmark
there. This is important to try when upgrading to the newer JMH
versions, since the minute differences in the build configurations may
attribute to the failures you are seeing."
If you'd follow that, you will notice that you also need to add jmh-generator-annprocess as the dependency, and make sure it runs before you run any test.