mardi 27 janvier 2015

maven error - package org.junit does not exist

I got a little trouble using maven and junit. Running junit test on its own works perfect, but building with Maven mvn clean test fails. I made sure that all tests are within "src/test/java" and all sources are within "src/main/java", so junit can find them (regarding to other questions this was the problem in many other cases).


So does anybody knows why I this is not working for me?


Error Message snipped:



/D:/pathToProject/myProject/src/test/java/myPackage/MyFile.java:[5,17] package org.junit does not exist


Pom.xml Snipped:



<...project information.../>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source />
<target />
</configuration>
</plugin>
</plugins>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Dividing a set of numbers in to two sets such that sum of elements in each set must be equal

i have made a java program for following problem statement -


"Dividing a set of numbers in to two sets such that sum of elements in each set must be equal "


input: array of integers


output:


"Yes"-if set can be divided in to two equal sum,


"No" -if can not be divided in to two equal sum,


"Invalid" -if integer array contains any other type of Integers(excepting positive integers)


and i have submitted the code to an online compiler and the code i have written has passed 8 test cases out of 10.i tried hard but i couldnt succeed finding those two test cases which failed . what are those two test-cases which failed ? here's the code -



public class CandidateCode
{

public static String partition(int[] arr) {
int sum = getSum(arr);
int half = sum / 2;
int out = 0;
int i = 0;

boolean flag = false;
if (hasZero(arr)) {
return "Invalid";
}
if (sum % 2 != 0) {
return "No";
}
if (arr.length == 2) {
if (arr[0] == arr[1]) {
return "Yes";
}
return "No";
}

else {


while (i < arr.length) {
if (arr[i] < half)
out += arr[i];
if (out == half) {
flag = true;
break;
}
i++;
}

}
if (flag)
return "Yes";
else
return "No";
}

public static int getSum(int[] arr) {
int result = 0;
for (int i = 0; i < arr.length; i++) {
result += arr[i];
}
return result;
}

public static boolean hasZero(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] <= 0) {
return true;
}

}
return false;
}
}

When running jasmine tests, how can I know if I am in a describe block, beforeEach block or it block?

I need to throw an exception if a utility is used outside of an 'it' or 'beforeEach' block in my tests. Example -



describe('some test', function(){

useUtil(); // should throw exception

beforeEach(function(){
useUtil() // should work
})

it('should test something', function(){
useUtil() // should work
})
})


The util creates spies, and I want to make sure they are create in a way that allows Jasmine to clean them after every suite.


How to compare User interface elements of a website after a code deployment?

I want to compare a website before and after a code deployment for any change in UI elements. Is there any tool online which allows for such comparisons?


Access ASP:Text Value with Watin

I've only started working with watin a few days ago and I'm having a slight problem. I am writing a very simple test to change the text of UserName. The code is:


Markup



<div class="col-md-10">
<asp:TextBox runat="server" autocomplete="off" ID="UserName" CssClass="form-control" placeholder="Username" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName"
CssClass="text-danger" ErrorMessage="The Username field is required." />
</div>


And my Test code is:



[TestClass]
public class TestClass
{
[TestMethod]
public void TestMethod1()
{
using (var browser = new IE("My Url"))
{
browser.TextField(Find.ByName("UserName")).TypeText("some text");
}
}
}


When ever I run the test I keep getting the following error:



Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'UserName' at about:blank



I've come across this question but still get the same error. Can someone please tell me where I'm going wrong. Thanks in advance for all your help and support.


Robolectric: ClassCastException: java.lang.ExceptionInInitializerError cannot be cast to java.lang.RuntimeException

I'm attempting to get Robolectric 2.4 working with my Cordova Project in Android Studio 1.0.2 and when I run the test ./gradlew clean test I get the following exception:



java.lang.ClassCastException: java.lang.ExceptionInInitializerError cannot be cast to java.lang.RuntimeException
at org.robolectric.internal.ReflectionHelpers.callInstanceMethodReflectively(ReflectionHelpers.java:68)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:115)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:268)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:122)
at de.dfki.telcoPortal.example.DeckardActivityRobolectricTest.setup(DeckardActivityRobolectricTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)


I have tried different solutions but not luck. I don't know what I made wrong. Could anyone help me with this error?


My top-level build.gradle looks like:



buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.14.+'
}
}

allprojects {
repositories {
mavenCentral()
}
}

apply plugin: 'com.android.application'
apply plugin: 'robolectric'

android {
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
compileSdkVersion 19
buildToolsVersion '21.1.2'
sourceSets {
main {
manifest.srcFile './src/main/AndroidManifest.xml'
res.srcDirs = ['./src/main/res']
assets.srcDirs = ['assets']

}
androidTest {
setRoot('src/test')
}
}
defaultConfig {
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
lintOptions {
abortOnError false
}
productFlavors {
}
buildTypes {
}


}
robolectric {
include '**/*Test.class'
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':CordovaLib')
compile 'com.android.support:support-v13:19.1.0'
androidTestCompile('junit:junit:4.12') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'ple`enter code here`xus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}

apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}


My Activity is:



public class CordovaApp extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
}


and my basic Test is



@Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class CordovaAppTest{

private CordovaApp activity;

@Test
public void testSomething() throws Exception {

activity = Robolectric.buildActivity(CordovaApp.class)
.create().get();
assertTrue(activity != null);
}
}

Testing fuelphp apps besides phpunit

I often using fuelphp, and testing with phpunit.


It started up to me as like, "Does any tools are able to test fuelphp apps?".


Fuelphp support phpunit. And I check sources of fuelphp, and the word 'phpunit' has been well-documented.


So , I think that it is difficult to use .


Does anyone know about it ?


Or, does anyone use another test tools with fuelphp ?