Eclipse Juno : TestNG installed but inaccessible - eclipse-plugin

I need to use testNG for a studies' project, so I tried to install the ecplipse plugin by two ways: first using a distribution package (I'm using Eclipse Juno on Archlinux) https://aur.archlinux.org/packages/eclipse-testng/ and the second time using the eclipse add-ons installer ("help">"install new softwares...") following these steps : http://selftechy.com/2012/01/09/setting-up-testng-with-eclipse
But, each time, I've this problem : The plug-in seems correctly installed but I do not find it in the menus, like it'd be disabled... for example, I can't see its window in
"Window">"Show view">"Other...">"java".
However, when I go to
"Help">"About Eclipse SDK">"Installation Details...">"Installed Software",
I see it well : "TestNG 6.8.0.20121120_1820 org.testng.eclipse.feature.group Cedric Beust"
So what's happening??

After you've installed the plugin simply right click on your class file -> Run As -> TestNG Test
Make sure your test methods are properly annotated, i.e.
public class Test {
#Test
public void test1(){
System.out.println("test1");
}
#Test
public void test2(){
System.out.println("test2");
}
}

Related

Maven install - SQL problem / suitable driver

I have two Maven Project with exactly same code.
I'm running project number one just from public static void main method and it connects to database and works perfectly, but when I use maven install and try to run it as a plugin in BukkitMC server it tells me all the time
"no suitable jdbc driver found"
I have dependencies at pom.xml in both project the same, so I'm pretty sure it works.
It's just all about this MAVEN INSTALL.
Have you got an idea?
public static void main(String[] args) {
App app = new App();
app.insertData("INSERT INTO users (login,password,email) VALUES ('a','b','c');");
}
Basically install goal do also package goal.
In package your project is archived (eg:jar) and after on install is deploy.
Could check what is inside archive(jar) and if not any sql-driver then you could search for the appropriate way to be packages from maven also with driver.
Other option is to add driver maybe manually on your server.

Intellij IDE Not Running Unit Tests

I am running IntelliJ IDEA 2018.3.1 and am attempting test a class with the integrated test runner. The test seems to compile but not run.
This is a multi-module Maven project, and other modules have tests that run. However, I have not been able to find any differences between the projects. The surefire plugin is specifically defined on this project, and <skipTests> is specifically set to false. I have reimported the project several times in case the maven configuration is affecting the built-in runner.
The image below is the only output I get. Debug/Breakpoints will not stop.
If anyone can help or throw possibilities at me, I would appreciate it.
Edit:
Here's a simplified version of the test I'm attempting to run:
package com.jason;
// imports
#RunWith(BlockJUnit4TestRunner.class)
public class MyTest {
private ClassUnderTest clazz;
private DaoClass dao;
#Before
public void setUp() {
// using Mockito to mock the DaoClass
// injecting the DAO into the ClassUnderTest
}
#Test
public void testMethod() {
Assert.assertTrue(true);
}
}
I attempt to run the test by right-clicking on the method annotated with #Test and clicking run. The option to run the test DOES appear in the context menu. When I do so, all that appears is the screenshot.
I have attempted to do the following to troubleshoot the issue:
In the pom.xml file for the appropriate module, I have manually specified the surefire plugin in the <build><plugins> section. I then did a reimport to pick up the changes.
I have put breakpoints in the code and run the test in debug mode.
I have attempted to log output, both with an slf4j logger and a System.out.println()
I have attempted to find any differences in the IDEA .iml file between a module where the tests run and this module where the tests do not run.
I have written a very simple test class, with a method annotated with #Test and containing the line Assert.assertTrue(true)
Edit 2
Attempting to run mvn test -Dcontrollername produces the following output:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project rma-svc: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
Edit 3
I've updated my Maven surefire plugin to 2.22.2 and am not seeing the forked JVM issue any longer. However, running mvn test -DskipTests=false outputs No tests were executed!

Running a WebDriver Test without using ANT, Maven, JUnit or Eclipse

I would like to know if it's possible to run a WebDriver test in Java using just a plain text editor, Firefox browser, Java SDK and WebDriver JAR?
I am trying to come up with the most "bare-metal" way to run a test without adding Test Runners, Test Frameworks, Dependency Managers into the mix.
I understand that this is not the "right" way to do things, but I am trying to find a way to create a new kind of WebDriver tutorial that will focus only on the API.
I am using OS X right now but instructions for Windows would be equally appreciated.
Running WebDriver is as simple as
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
The only thing that you need is a correct classpath, which is just selenium-java-2.38.0.jar and supporting libraries, namely: guava-15.0.jar json-20080701.jar commons-exec-1.1.jar httpcore-4.3.jar httpclient-4.3.1.jar commons-logging-1.1.1.jar
Or, as per JimEvans, you can download standalone selenium-server-standalone-2.40.0.jar that has all dependencies included.
Firstly record and run the script you want to do then export it as junit4 test suite and save. Second copy the full code and aste it in eclipse then you can get the option "Run as junit4 test" while running code.

TeamCity - Testing with JUnit

I am using Intellij Idea version 12 (ultimate). Just installed Team City (version 8). One default agent, running in linux.
I've created a very simple test application:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
public int sum(int x, int y) {
return x+y;
}
}
... and a very simple test...
import junit.framework.Assert;
import org.junit.Test;
public class MainTest {
#Test
public void testSum() throws Exception {
Main test=new Main();
Assert.assertEquals("Sum should be 7",7,test.sum(4,4));
}
}
If I run this in IntelliJ, the test gets run and fails just like it should.
If instead I commit this project and push it up to github, TeamCity sees the change and begins a build. The build fails fairly quickly with the following errors:
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:1: package junit.framework does not exist
import junit.framework.Assert;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:2: package org.junit does not exist
import org.junit.Test;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:12: cannot find symbol
symbol : class Test
location: class MainTest
#Test
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:15: cannot find symbol
symbol : variable Assert
location: class MainTest
Assert.assertEquals("Sum should be 7. Loser!!",7,test.sum(4,4));
^
So yeah, I see that TeamCity is not seeing JUnit.
On the TeamCity Discussion forum, one respondent to my question there asked me if junit.jar was added as a dependency (module or library) in the build. It was listed as a module dependency, but for kicks I tried it as a library dependency. I also tried checking and unchecking export and trying the compile and test scopes, but each time I get the same errors. My run configuration is shared.
I am not using Ant or Maven. Perhaps someday, but I'd like to start as simple as possible.
Clearly, I'm missing something, but the documentation on the subject is sparse.
Thank you.
So I heard back from Jetbrains tech support this and, in the interest of completeness and saving someone else the trouble, here's the response I received:
Seems the problem is that junit.jar is not placed in version control
under your project. In order to build your project on TeamCity agent,
the project ideally should be self contained. In your case junit.jar
only exists on your local machine, I suppose there is no such file on
agent at required location. So you have two options actually: put
junit.jar under version control into your project, or define global
library in IDEA and configure this global library on IDEA Project
runner page (Check/Reparse must be started), after that put library
files on all of the agents where your build will be executed.
Personally, I think the first approach is much simpler and better.
I added junit to version control and now the build works properly in TeamCity.

How to run an exported selenium test case using TestNG in Eclipse

I recorded a test case using Selenium IDE 1.10.0. I exported the case as Java/TestNG/Remote Control.
My Eclipse version is 4.2.0 and I installed TestNG plug-in version 6.8
I am wondering how can I create a project within the eclipse to run this exported test case?
Please give me some instructions or share with me some online tutorial / documentations. Thanks!
Below is the java code generated by the Eclipse:
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
public class SearchDonor extends SeleneseTestNgHelper {
#Test public void testSearchDonor() throws Exception {
// set overall speed of the test case
selenium.setSpeed("4000");
selenium.open("/?html=openid");
selenium.click("css=input[type=\"submit\"]");
selenium.waitForPageToLoad("30000");
Thread.sleep(4000);
selenium.click("id=cmp_admin");
selenium.waitForPageToLoad("30000");
selenium.click("id=quicksearch_anchor");
selenium.click("css=img[alt=\"Member\"]");
selenium.waitForPageToLoad("30000");
selenium.type("id=search_name", "suzy");
selenium.click("css=input[type=\"image\"]");
selenium.click("link=Balagia, Suzy");
selenium.waitForPageToLoad("30000");
}
}
After some trial and errors. I managed to execute the exported code in Eclipse as TestNG Test. Here are the steps I took to make it compile.
1.created a Java Project within the Eclipse
2.add a class to the Java Project
2a. I copied and pasted the code into the newly created the class
3.Right click on the project>build path>configure build path
3a. on the Java Build Path window select libraries>Add External JARS, then adding all the JAR files from Selenium Java Driver folder (e.g. folder name in this case is libs), plus selenium-java-2.31.0.jar and selenium-java-2.31-src.jar
4.click the Run icon next the debug icon on the top menu bar, Run AS TestNG Test
My code is compiling, but I got some exception errors. I am getting stared on a TestNG test case!