Can't use Processing 3 in IntelliJ - intellij-idea

Well the thing is simple i guess.
I'm kinda of new in Java and IntelliJ but i wanted to use Processing in IntelliJ because of the auto - complete.
Well i've added the core.jar library from processing.
I've wrote the code (i tried with only what it is inside main and still won't work so i guess there is no problem with the overridden functions).
package com.company;
import processing.core.PApplet;
class MainClass extends PApplet {
#Override
public void setup() {
super.setup();
}
#Override
public void draw() {
super.draw();
}
#Override
public void settings() {
super.settings();
}
public static void main(String args[]) {
PApplet.main("Test");
}
}
(edit: i tried with MainClass and com.company.MainClass and didn't work either)
And when i tried to run it this pops out.
java.lang.RuntimeException: java.lang.ClassNotFoundException: Test
at processing.core.PApplet.runSketch(PApplet.java:10697)
at processing.core.PApplet.main(PApplet.java:10504)
at processing.core.PApplet.main(PApplet.java:10486)
at com.company.MainClass.main(MainClass.java:23)
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at processing.core.PApplet.runSketch(PApplet.java:10690)
... 3 more

Your error is telling you that it can't find a class named Test. You're using a String value of "Test". Do you have a class named Test?
Your main class is called MainTest. But you're passing in a String value of "Test" to the PApplet.main() function. Where are you getting the "Test" value?
It should be:
PApplet.main("MainClass");
Or possibly:
PApplet.main("com.company.MainClass");
By the way, if autocomplete is the main reason you're switching to an IDE, I'd actually recommend sticking with the Processing editor. Using an IDE too soon will hide a lot of the stuff you need to learn from you.
And in the future, please don't post screenshots of code or error messages. Copy and paste them as text instead.

Related

initializationError when running Junit test in static

I have been on a search recently for an answer to my question and I cannot seem to find it. I am trying to execute a simple test to run a JUnit test in static. When I try to execute the test I receive the following Failure.
java.lang.Exception: Method SimpleINt()should not be static.
I have JUnit 4 and hamcrest installed and pathsbuilt.
(I am still new to Selenium/Java so I am sure there is an easy explanation for this.)
package iMAP;
import org.junit.Test;
public class Test1 {
#Test
public static void SimpleINt ()
{
int i = 34;
System.out.println(i);
}
}
The JUnit documentation for #Test states:
The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure.
So, what is implicitly said here: the expectation is that #Test is only used for non static methods.
Beyond that: don't use keywords because you can. Learn what they mean. And static is something that you rather avoid (instead of using it all over the place).
Junit Methods should not be static as much I read and study. Just delete Static and try this:
package iMAP;
import org.junit.Test;
public class Test1 {
#Test
public void SimpleINt ()
{
int i = 34;
System.out.println(i);
}
}

General Fixture Setup with PowerMockito and #BeforeClass

I have a test where I configure some general fixtures however after using PowerMockRule the static variables which I configure in my #BeforeClass method reset to null. This causes the following test to fail however if you remove PowerMockRule it passes.
public class Test
{
#Rule
public PowerMockRule rule = new PowerMockRule();
private static String MyString;
#BeforeClass
public static void setupClass() throws Exception
{
MyString = "FOO";
}
#org.junit.Test
public void test() throws Exception
{
assertEquals("FOO", MyString);
}
}
I have the answer, but you are not going to like it.
Short answer:it looks like a defect in PowerMock, so create a issue in our bug tracker
Long answer: As you may know the PowerMock to be able mock static, private and so on loads classes by custom class loader and modified byte code. Then #PowerMockRunneris used then PowerMock can control loading a test class and the test class is also loaded by custom class loader. In case if another jUnitRunner runs test and the PowerMockRuleis used, then the test class and all other classes that is needed for test are loaded with standard class loader. PowerMock reloads all these classes either by using deep coping with serializing/deserializing or by using objenesis. So as class is reloaded all static fields which was initialised are null.
I've briefly checked code and I haven't found test for your cases and that we processed #BeforeClass, so create a issue in our bug tracker and I'll check it deeply.
By the way, please, also point which version do you use and which dependencies do you use.

get Annotation of test method in testNG ITestListener

I am trying to integrate TestLink with TestNG
Approach is below
1>Write ITestListner with onTestFailure and onTestSuccess
2> get Annotation of the method(like testName which will be equivalent to test name in testlink) which is being failed/success in a variable
3>Make connection with TestLink using API available and update the test case.
However I am struggling to find method Annotation value in ITestListner and requirement is to get annotation values in ITestListner only so that correct test cases can be updated in Test_link
Can someone please help me how to get Test Method annotation value in ITestListner or any other approach in which i can integrate testlink update with TestNG
Hi Thanks niharika for help
,First of all you are correct in explaining use of TestNG but we are using TestNG for Selenium and already there are around 1000 test cases writen in test Methods and we have to live with that
Some how i have figured the solution ,we can still get the testName of the test method using two listners
This is just work around I am not sure if this is the best approach but as of now solving my purpose
package com.automation.testng.listner;
import org.testng.*;
public class MyIInvokeMethodListner_TestName_TestLink implements IInvokedMethodListener {
public static String testName;
public void afterInvocation(IInvokedMethod arg0, ITestResult arg1) {
// TODO Auto-generated method stub
}
public void beforeInvocation(IInvokedMethod m, ITestResult tr) {
// TODO Auto-generated method stub
//This give the Annotation Test object
org.testng.annotations.Test t=m.getTestMethod().getMethod().getAnnotation(org.testng.annotations.Test.class);
MyIInvokeMethodListner_TestName_TestLink.testName = t.testName().toString();
}
}
MyITestListner goes like below
package com.automation.testng.listner;
import org.testng.*;
public class MyITestListner_TestLink extends TestListenerAdapter {
/*IAnnotationTransformer at;
public Listner_1()
{
this.at = new Annotation_listner();
}*/
#Override
public void onTestFailure(ITestResult tr)
{
System.out.println("Hurray !I am being inboked from Test listner");
MyIInvokeMethodListner_TestName_TestLink a = new MyIInvokeMethodListner_TestName_TestLink();
System.out.println(MyIInvokeMethodListner_TestName_TestLink.testName);
}
public void onTestSuccess(ITestResult tr)
{
MyIInvokeMethodListner_TestName_TestLink a = new MyIInvokeMethodListner_TestName_TestLink();
System.out.println(MyIInvokeMethodListner_TestName_TestLink.testName);
}
}
Basically we are getting the method and then using Test Annotation class setting the static variable which can be used in MyITestListner
The ITestListener is the one which is used after <test> tag. For getting the method name and annotation specifics, you need to implement IInvokedMethodListener and in the after/before methods of this interface, and use something like method.getTestMethod().getMethodName() to get the executing method name.
If you are adding testName at the method level, I think you are doing it wrong since the help of testng mentions this "The name of the test this test class should be placed in. This attribute is ignore if #Test is not at the class level."
If you are indeed specifying the #Test at your class level then you can get it as below :
method.getTestMethod().getTestClass().getTestName()
A bit ugly and you probably want to wrap those parts in null checks in your code but this is how you get the testName specified in the annotation from the ITestResult:
iTestResult.getMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class).testName()

How to implement AbstractWebdriverEventListener in a script

I have created a file with the name SeleniumTestListener.java and I have written the below code:
#override
#AfterMethod(alwaysrun=true)
public class UITestNGListener extends AbstractWebDriverEventListener
{
// TODO Auto-generated method stub
#Override
#AfterTest(alwaysRun=true)
public void onException(Throwable exception, WebDriver driver) {
System.out.println("Failed Failed Failed");
}
Now when I am trying to run the script(purposely making it to fail after login into my application)
But it is failing with a configuration issue
org.testng.TestNGException:
Method onException requires 2 parameters but 0 were supplied in the #Configuration annotation.
Can someone please help how to pass the values(throwable exception, webdriver driver) for this?
Thanks much for the help
You can't use #AfterMethod on a class.
If you specify parameters in a test method, you need to pass these parameters either with the #Parameters annotation or by using a #DataProvider.

junit.framework.AssertionFailedError: No tests found in register

I'm having a problem getting this test case to work. Can anyone point me in the right direction? I know I'm doing something wrong, I just don't know what.
import org.junit.*;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
#SuppressWarnings("deprecation")
public class register extends SeleneseTestCase {
Selenium selenium;
private SeleniumServer seleniumServer;
public static final String MAX_WAIT = "60000";
public final String CRN = "12761";
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setAvoidProxy(true);
rc.setSingleWindow(true);
rc.setReuseBrowserSessions(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://google.com/");
seleniumServer.start();
selenium.start();
}
#Test
public void register_test() throws Exception {
//TESTS IN HERE
}
#After
public void tearDown() throws Exception {
selenium.stop();
// Thread.sleep(500000);
}
}
And I'm getting the following errors:
junit.framework.AssertionFailedError: No tests found in register
at jumnit.framework.TestSuite$1.runTest(TestSuite.java:97)
I'm stumped.
You can't both extend TestCase (or SeleniumTestCase) and also use JUnit annotations (#Test). The test runners for JUnit3 and 4 are different, and my assumption is when JUnit sees that you've extended TestCase, it uses the old runner.
Remove the #Test annotation, and instead follow the old convention of naming your test with the word "test" prefixed, and that will fix it.
public void testRegister() throws Exception {
//TESTS IN HERE
}
PS. I'd recommend following more standard Java naming conventions, such as camel casing.
PPS. Here's a link that explains this in more detail.
This means you did not created method names starting with test in following test cases class what you running currently
I was able to solve this error in my case--that is, running tests with a <junit> Ant task--by pointing to a 1.7 or later version of Ant. Ant 1.7+ honors nested <classpath> elements, in which I was pointing to a JUnit 4.x jar, which as CodeSpelunker indicated understands #Test annotations. http://ant.apache.org/faq.html#delegating-classloader provided the aha moment for me.
I'm using mockk in Kotlin for Android and I had this error.
My class was declared like this (autogenerated by Android Studio):
class MyClassTest : TestCase() {
but removing TestCase fixed the error
class MyClassTest {