Reputation: 3550
Hello I am new to Gradle. We just switch from Maven to Gradle and I have some difficulties in understanding of Gradle test task. Here is my class:
public class Money {
private final int amount;
private final String currency;
public Money(int amount, String currency) {
if (amount < 0) {
throw new IllegalArgumentException("illegal amount: [" + amount + "]");
}
if (currency == null || currency.isEmpty()) {
throw new IllegalArgumentException("illegal currency: [" + currency + "]");
}
//this.amount = 15;
this.amount = amount;
this.currency = currency;
}
public int getAmount() {
return amount;
}
public String getCurrency() {
return currency;
}
}
And here is my test (using TestNG):
@Test
public class MoneyManyValuesTest {
public void testConstructor() {
Money money = new Money(10, "USD");
assertEquals(money.getAmount(), 10);
assertEquals(money.getCurrency(), "USD");
money = new Money(20, "EUR");
assertEquals(money.getAmount(), 20);
assertEquals(money.getCurrency(), "EUR");
}
}
When I run test (with gradle "test" task) everything looks like OK.
But then I want my test to fail, so I tweak last row of my test like this:
assertEquals(money.getCurrency(), "EUR want error here");
Run gradle "test" again and test still passes with msg:
2:40:26 PM: Executing external task 'test'...
money:compileJava UP-TO-DATE
money:processResources UP-TO-DATE
money:classes UP-TO-DATE
money:compileTestJava
money:processTestResources UP-TO-DATE
money:testClasses
money:test
BUILD SUCCESSFUL
What is going on here?
Here is my build script
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java';
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
testCompile 'org.testng:testng:6.3.1'
testCompile 'org.mockito:mockito-all:1.9.0'
testCompile 'org.easytesting:fest-assert:1.4'
testCompile 'org.hamcrest:hamcrest-all:1.1'
}
test {
useTestNG()
}
}
Upvotes: 1
Views: 1149
Reputation: 3550
I am using IntelliJ IDEA. And my IDE saves my source code automatically. I am so accustomed to this feature so I even forgot that IDEA does this for me. Looks like whenever I ran Gradle "test" task, IDEA does not saves my source code automaticly. But if I save it manually everything works fine.
Upvotes: 1