Unit tests test exactly that ie a “unit of code”. Generally you would have a separate project that would reference a module from your main project and then test each Sub with an input and then validate that input. You would also have tests that test with a bad input and validate that the error is handled it correctly.HI, All
I know about this term only theoretically.
How should it look in B4X development ? Especially in B4R ...
Any example of codes ?
I did not see, and also cannot imagine yet. Do you have an example of such Java repo to check ?not yet figured out a good way
assert
thumbnailator/src at master · coobird/thumbnailator
Thumbnailator - a thumbnail generation library for Java - coobird/thumbnailatorgithub.com
/**
* Test for
* {@link Thumbnailator#createThumbnail(File, File, int, int)}
* where,
* <p>
* 1) Input File does not exist.
* <p>
* Expected outcome is,
* <p>
* 1) Processing will stop with an IOException.
*
* @throws IOException
*/
@Test
public void testCreateThumbnail_FFII_nonExistentInputFile() throws IOException {
/*
* Actual test
*/
File inputFile = new File("foo.jpg");
File outputFile = new File("bar.jpg");
try {
Thumbnailator.createThumbnail(inputFile, outputFile, 50, 50);
fail();
} catch (IOException e) {
assertEquals("Input file does not exist.", e.getMessage());
}
}
Yes, exact for this the topic has been created. To understand the subject...topic for debate
function assert(condition)
{
if (!condition) {
throw "Assertion failed! See stack trace for details";
}
}
assertEquals()
The assertEquals() method compares two objects for equality, using their equals() method.
Here is a simple example:
Java:import org.junit.Test; import static org.junit.Assert.*; public class MyUnitTest { @Test public void testConcatenate() { MyUnit myUnit = new MyUnit(); String result = myUnit.concatenate("one", "two"); assertEquals("onetwo", result); } }
First the myUnit.concatenate() method is called, and the result is stored in the variable result.
Second, the result value is compared to the expected value "onetwo", using the assertEquals() method.
If the two objects are equal according to their implementation of their equals() method, the assertEquals() method will return normally. Otherwise the assertEquals() method will throw an exception, and the test will stop there.
This example compared to String objects, but the assertEquals() method can compare any two objects to each other. The assertEquals() method also come in versions which compare primitive types like int and float to each other.
What does it mean ?...IF practice is useful in RAD tool like B4X
I think it is useful if your app has many forms, inputs or calculations such as Web API and accounting.What does it mean ?
When and where are the unit tests useful ? No use in B4X ?
Sub AppStart (Args() As String)
Dim a As Int = 3
#if DEBUG
' check against known value
assertEquals(a,3)
#end if
Log("Value = " & a)
End Sub
#if DEBUG
Sub assertEquals(o As Object,testValue As Object)
If o <> testValue Then
Log($"Test failed : object ${o} <> ${testValue}"$)
Else
Log($"Test passed : object ${o} = ${testValue}"$)
End If
End Sub
#End If
I see that B4R project is small and straight forward. I don't know if unit test is suitable for this platform.Especially in B4R ...
You just did not see real projectsI see that B4R project is small and simple
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?